Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ViewPager和FragmentTabHost两次显示内容_Android_Android Fragments_Android Viewpager_Android Tabhost_Android Support Library - Fatal编程技术网

Android ViewPager和FragmentTabHost两次显示内容

Android ViewPager和FragmentTabHost两次显示内容,android,android-fragments,android-viewpager,android-tabhost,android-support-library,Android,Android Fragments,Android Viewpager,Android Tabhost,Android Support Library,我有包含Fragment的选项卡,我想提供左右移动的滑动手势。我在片段和活动的内部使用它。我使用support.v4包中FragmentTabHost的ViewPager内部(需要使用>=API 10)。问题是,寻呼机开始从版面顶部显示内容,而tabhost先显示选项卡,然后显示内容。我当然想要第二种行为。所以我看到的内容是两次,一次有标签,一次没有。这是我的布局xml文件。请注意,我在tabhost(@+id/relative_header)上方还有一些其他视图,因此操作栏选项卡不适合这种情况

我有包含
Fragment
的选项卡,我想提供左右移动的滑动手势。我在
片段和活动的内部使用它。我使用
support.v4
包中
FragmentTabHost
ViewPager
内部(需要使用>=API 10)。问题是,寻呼机开始从版面顶部显示内容,而tabhost先显示选项卡,然后显示内容。我当然想要第二种行为。所以我看到的内容是两次,一次有标签,一次没有。这是我的布局xml文件。请注意,我在tabhost
(@+id/relative_header)
上方还有一些其他视图,因此操作栏选项卡不适合这种情况。我已经尝试将寻呼机移动到
realtabcontent
或更高的位置,但运气不佳

 <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>


我不确定,但我假设其中一个与另一个不兼容,但我不知道应该使用哪个compinion在片段选项卡之间提供滑动手势。知道我做错了什么吗

好吧,我写这个答案是为了将来有同样问题的人。我误解了每个布局的作用
ViewPager
TabHost
做着或多或少相同的事情。要启用滑动手势,我应该使用ViewPager。为了添加标签,我使用了这个库,也是在2014年2月14日,android团队发布了一个本机布局。棘手的一点是tabhost的内容和选项卡在同一布局中,但它不能提供滑动手势