Question

I have tabs that contains Fragment and i want to provide the swipe gesture to move right and left. I'm using it inside of Fragment and inside of activity. I use ViewPager inside of FragmentTabHost both from support.v4 package (need to work on >=API 10). The problem is that the pager starts showing the content from the top of layout and tabhost is showing the tabs first and then the content. Of course i want the second behavior. So what i see is the content twice, one with tabs and one without. Here is my layout xml file. Notice that i have also some other views above the tabhost (@+id/relative_header) so action bar tabs don't fit in this case. I've already try to move pager into realtabcontent or above it with no luck.

 <android.support.v4.app.FragmentTabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/relative_header" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"> 
        </TabWidget>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0" />
        <FrameLayout
            android:id="@+android:id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </LinearLayout>
</android.support.v4.app.FragmentTabHost>

I'm not sure but I assume that one of them is incompatible with the other, but i don't know which compination should use to provide swipe gesture between fragments tabs. Any idea about what I'm doing wrong?

Was it helpful?

Solution

Well, i'm writing this answer for anyone will have the same question in future. I misunderstood the role of each layout. ViewPager and TabHost doing more or less the same thing. To enable the swipe gesture i should have used ViewPager. To add tabs to this, i used the library PagerSlidingTabStrip , also on Feb. 14 2014 seems that android team released a native layout for this: PagerSlidingTabStrip . The tricky point was that tabhost has content and tab in the same layout but it cannot provide the swipe gesture.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top