Search code examples
androidactionbarsherlockandroid-tabhost

Reusing XML in android by <include>


I am using ActionBarSherlock for tabs in android

main_fragment_desc_list_view.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include layout="@layout/screen_parent_topbar" />

    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <FrameLayout
            android:id="@+id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v4.app.FragmentTabHost>

    <include layout="@layout/screen_parent_bottombar" />

</LinearLayout>

What i am having trouble with ?

Even though i have added the code <include layout="@layout/screen_parent_bottombar" /> it is not shown in the screen when i execute the code

enter image description here

What changes should i need to make here so that i am able to get my bottom layout included at the bottom ?


Solution

  • Your android.support.v4.app.FragmentTabHost has a height of MATCH_PARENT and therefore the layout at the bottom will not appear.

    One alternative would be using a RelativeLayout to create the header/content/footer layout:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <include android:id="@+id/header"
                 android:layout_alignParentTop="true"
                 layout="@layout/screen_parent_topbar" />
    
        <include android:id="@+id/footer"
                 android:layout_alignParentBottom="true"
                 layout="@layout/screen_parent_bottombar" />
    
        <android.support.v4.app.FragmentTabHost
            android:layout_below="@id/header"
            android:layout_above="@id/footer"
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <FrameLayout
                android:id="@+id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </android.support.v4.app.FragmentTabHost>
    
    
    </RelativeLayout>