Search code examples
androidxmlandroid-layoutfooter

i want to add footer on all the tabs in my application to show weather


i have added footer in tab activity footer is shown in all tabs but problem is that it comes over the data so data at bottom is not visible.

here is my code of xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

<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="match_parent"
    android:id="@+id/relativ_layout"

    tools:context=".MainActivity" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ff8800"

                android:orientation="horizontal" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0" >



               </FrameLayout>

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom" >


                </android.support.v4.view.ViewPager>



        </LinearLayout>



    </TabHost>

    // footer *************************************************
    <RelativeLayout
            android:id="@+id/footer"
            android:layout_width="match_parent"

            android:layout_height="wrap_content"           
            android:layout_alignParentBottom="true"
            android:background="#F00000"
            android:gravity="bottom" >

        <TextView
            android:layout_width="wrap_content"            
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:text="Fixed Footer"
            android:textColor="#000"
            android:textSize="20sp" />
                </RelativeLayout>    

            //********************************************

</RelativeLayout>








 <FrameLayout
    android:id="@+id/Frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >



 </FrameLayout>



 <LinearLayout
        android:id="@+id/navigation_drawer"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
       android:orientation="vertical"
        android:background="@android:color/white">




          <RelativeLayout      
        android:layout_width="match_parent"
    android:layout_height="150dp"
    android:clickable="true"
    android:focusable="true"
    android:background="@drawable/navigationdrawer"


    >



         <TextView 
             android:id="@+id/txtemail"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="[email protected]"
             android:layout_alignParentBottom="true"
             android:layout_marginLeft="10dp"
             android:layout_marginBottom="10dp"/>

     </RelativeLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="15dp"
            android:paddingTop="20dp"

            android:textColor="@android:color/darker_gray"
            android:textStyle="bold"
            android:paddingLeft="10dp"
            android:paddingRight="16dp"
            android:text="TITLE" />

            <ListView
        android:id="@+id/list_slider"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
       android:listSelector="@drawable/list_selector"
        android:divider="@color/list_divider"
        android:choiceMode="singleChoice"
        android:dividerHeight="0.3dp"
         />



    </LinearLayout>

</android.support.v4.widget.DrawerLayout>   

please tell me how to add footer below the data.


Solution

  • You can do this by using nested relative layouts, like below

    <!-- Header -->
    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:gravity="center" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Header"
            android:id="@+id/textView" />
    </RelativeLayout>
    
    <!-- Footer -->
    <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Footer"
            android:id="@+id/textView2" />
    
    </RelativeLayout>
    
    <!-- Content -->
    <!-- Place your content in this layout-->
    <RelativeLayout
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/footer"
        android:layout_below="@id/header"
        android:gravity="center" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Content"
            android:id="@+id/textView4" />
    </RelativeLayout>
    

    Result: (Borders added for clarity)

    Result