I've read about using ActionBar Tabs
, but I want to structure my layout so that I have the tabs somewhere not at the top (after a View
) and the layout form the tab downwards to the end of the screen would be the area that changes fragments.
I've looked at a couple of SO questions that are sort of similar, and most mention ViewPager
I think, but I haven't found any concrete answers as how to implement this. So how do I get my layout to have a common View
, and then right underneath, the tab part? Can this be done with TabHost
?
To better illustrate... this is my current XML
for the layout (I deleted some attributes to keep it short):
<!-- top most layout -->
<ScrollView 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"
tools:context="com.xxxx.req.FinancialsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Layout that's always visible -->
<LinearLayout
android:id="@+id/"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<!-- This is where I want to have two tabs next to each other -->
<!-- Right underneath the tabs, I want a FrameLayout so I can
switch between two fragments -->
</LinearLayout>
</ScrollView>
So how do I get my layout to have a common View, and then right underneath, the tab part?
Put "the tab part" right where your code comments say that you want "the tab part". While that cannot be accomplished via action bar tabs, such tabs are deprecated anyway starting with the "L" Developer Preview. A ViewPager
and tabbed indicator (e.g., PagerTabStrip
) or a FragmentTabHost
can go where your comments indicate.
Note that TabHost
would not be practical, given that you want the tabs to be fragments -- you are better served using FragmentTabHost
.