ViewPager无法与TabLayout一起正常工作

时间:2016-03-31 08:17:02

标签: android android-design-library android-tablayout

我有下一个布局的片段

deducted.number

当我在冷启动应用程序时,我会看到正确的TabLayout包含所有需要的标签页和2个第一页到viewpager(为viewpager设置偏移限制1)。

将ViewPager刷到3页后,我什么也看不见。看起来ViewPager中缺少片段,但我看到日志和片段工作正常。

如果我将应用程序发送到后台并转回,则所有页面都将可见。

如果我删除tablayout并删除所有缓存,则此错误不会重复。

初始化代码:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="54dp"
        app:tabGravity="center"
        app:tabMode="scrollable"
        app:tabSelectedTextColor="@android:color/white"
        app:tabTextColor="@color/tab_color"
        app:tabIndicatorHeight="3dp"
        app:tabTextAppearance="@style/Discover.TextAppearance.Tab"/>
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
    </FrameLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

你能传递更多代码吗?你应该考虑RelativeLayout,然后跳过FrameLayout。