Android设计支持库中的TabLayout重叠内容问题

16

我正在使用设计支持库中引入的新TabLayout。我的代码类似于:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/lines_coordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:elevation="4dp"/>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.design.widget.CoordinatorLayout>

</LinearLayout>

问题是标签重叠了内容片段显示的顶部。我该如何解决这个问题?我使用的是Github上的示例中的TabLayout,因此我相信我的代码没有问题。我已经有一个工具栏,因为我在导航抽屉中的一个片段中使用选项卡,所以我从AppBarLayout中将其删除了。

1个回答

48

您需要将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到您的 ViewPager 中:这将使视图的高度低于 AppBarLayout 而不是完全使用 match_parent 的高度。


非常感谢,已经修复了 :) - qwertz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接