TabLayout 覆盖片段中的内容

TabLayout covered content in fragments

我最近添加了一个包裹在 AppBarLayout 中的 TabLayout,之前包含 toolbar,但现在由 TabLayout 托管的片段应该在它下面,被 TabLayout 覆盖,我尝试将 android:layout_below="@+id/tablayout" 添加到我的 ViewPager (其中包含片段),并将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到 TabLayout 本身,但是这两种方法都不起作用, 这是我的布局文件的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.jackz314.todo.MainActivity"
    android:id="@+id/total_main_bar"
    >

    <include
        android:id="@+id/include"
        layout="@layout/content_main"
        app:layout_anchor="@+id/app_bar_layout"
        app:layout_anchorGravity="left|bottom"
        />

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/app_bar_layout"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:tabMode="fixed"
            app:tabGravity="fill" />

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

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

请注意,片段的布局包含在“content_main 中,它位于包含部分中。我对 Android 很陌生,因此非常感谢任何帮助或建议.

检查并修改布局文件中的各种内容后,我将 ViewPager 从包含的布局文件移动到包含 TabLayout 的同一文件,然后应用 app:layout_behavior="@string/appbar_scrolling_view_behavior"ViewPager 解决了这个问题。 (如果它不在您的字符串文件中,android.support.design.widget.AppBarLayout$ScrollingViewBehavior 就是它的值)

坦率地说,我仍然很困惑为什么这会奏效(因为我尝试将相同的属性应用于包含部分,但那没有奏效),所以如果有人能帮助我解决这个问题,那会很棒。