Sachin Solanki Sachin Solanki - 4 months ago 14
Android Question

I want to set a footer with menu and I want to set icons equally divided as per the screen

This is my .xml file and I just want to set all image view in horizontally in
every screen... I tried but it's not happening.. help me for this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
tools:context="com.example.sachin.attendence.MainActivity">


firstly i set relative layout
and all imageview as a menu


<ImageView
android:id="@+id/imageViewFooter2"
android:layout_width="60dp"
android:layout_weight="1"
android:layout_height="60dp"
android:layout_marginLeft="100dp"
android:background="@drawable/ic_launcher"
android:layout_alignParentBottom="true"
/>

<ImageView
android:id="@+id/imageViewFooter3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="1"
android:background="@drawable/att"
android:layout_marginLeft="150dp"
android:layout_alignParentBottom="true"
/>

<ImageView
android:id="@+id/imageViewFooter4"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="1"
android:scaleType="fitXY"
android:layout_marginLeft="250dp"
android:background="@drawable/omlogo"
android:layout_alignParentBottom="true"
/>
<View
android:layout_width="match_parent"
android:layout_height="01dp"
android:background="#cec5ce"
android:layout_above="@id/imageViewFooter3"
android:id="@+id/view">

</View>
</RelativeLayout>


this was my .xml file

Answer

I assume you want to reuse your footer in other screens. in that case you really should create different XML file just for the footer, and include it.

the following example footer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="#bbb" 
    android:orientation="horizontal">

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/icon" />  <!-- your image here -->

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/icon" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/icon" /> 
</LinearLayout>

I created simple drawable icon which i'm using in this example

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <size
        android:width="48dp"
        android:height="48dp" />
    <solid android:color="#757" /> <!-- your background-->
</shape>

To include your footer.xml file in any screen, use include tag like so:

<include
    layout="@layout/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" />
Comments