Android 设计支持 TabLayout 重叠内容

标签 android layout tabs android-toolbar androiddesignsupport

我正在使用设计支持库中引入的新 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>

问题在于,选项卡与 fragment 显示的内容顶部重叠。我怎样才能解决这个问题?我在 Github 上的示例中使用 TabLayout,所以我相信我的代码没有问题。我已经有一个工具栏,因为我在抽屉导航的 fragment 中使用选项卡,所以我从 AppBarLayout 中删除了它。

最佳答案

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

关于Android 设计支持 TabLayout 重叠内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30674648/

相关文章:

java - 想知道如何通过双击和拉伸(stretch)来缩放图像

css - 如何让一个 div 排在另一个 div 的右边而不是下面?

android-layout - 如何在android中调整PIP模式的大小

Python:在写入 csv 文件时避免列的覆盖/不可读

jquery - 关闭点击自身和外部的基于 jQuery 的选项卡

android - 确定 Android 中安装的应用程序使用的权限列表

java - 如何在 ListView 中使用新的自定义 View ?

javascript - 如何制作 Bootstrap 选项卡 "auto play"

android - Android 中的 SSL 握手失败

android - 如何制作可滚动的应用程序小部件?