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 中删除了它。

4

1 回答 1

48

您需要添加app:layout_behavior="@string/appbar_scrolling_view_behavior"到您的ViewPager: 这就是将 View 的高度更改为低于AppBarLayout而不是完整match_parent高度的原因。

于 2015-06-05T20:12:28.210 回答