【问题标题】:ViewPager and FragmentTabHost display content twiceViewPager 和 FragmentTabHost 显示内容两次
【发布时间】:2014-02-04 13:00:04
【问题描述】:

我有包含Fragment 的标签,我想提供滑动手势来左右移动。我在Fragment 和活动内部使用它。我在FragmentTabHost 中使用ViewPager 都来自support.v4 包(需要处理> = 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>

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

【问题讨论】:

    标签: android android-fragments android-viewpager android-tabhost android-support-library


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多