Android 包含的布局包括父布局

Android 包含的布局包括父布局,android,xml,android-layout,android-studio,Android,Xml,Android Layout,Android Studio,我的主要活动在AppBarLayout中有一个工具栏,下面有一个包含: <?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"

我的主要活动在AppBarLayout中有一个工具栏,下面有一个包含:

<?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"
    android:fitsSystemWindows="true"
    tools:context="com.zhephyr.somedaytoday.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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/colorPrimaryDark"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <include layout="@layout/activity_chrono_tab"/>

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

包含的布局是一个相对布局,其中一个表格布局连接到一个ViewPager:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".ChronoSwipeViewActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorVariant"
        android:weightSum="1">

        <android.support.design.widget.TabLayout
            android:id="@+id/chrono_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            app:tabMode="fixed"
            android:background="@color/colorVariant"/>
    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@android:drawable/ic_dialog_email"
        android:layout_margin="@dimen/fab_margin"
        app:fabSize="normal"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/chrono_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/tabs" />
</RelativeLayout>

我目前遇到的问题是,包含的布局位于我的主布局之上,占据了整个屏幕。我看不到工具栏,因为它正在被覆盖。我希望包含的布局只填充工具栏下方的区域。我已尝试将
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
放置在两个版面和include中,但均无效。有人知道发生了什么吗

更新

显示的活动如下所示:

此活动应在此活动中显示,且不显示应用程序标题:


将包含版面的根目录更改为
android:layout\u height=“wrap\u content”

目前,它是
match_parent
,因此它将占据填充整个屏幕的父屏幕的高度

您还需要在
中添加
android:layout_down=“@id/toolbar”
,将其放置在工具栏下方。默认情况下,
RelativeLayout
视图
放置在左上方,因此添加此属性将告诉它在工具栏下方启动包含的布局

注意下面代码中的最后两行

<RelativeLayout 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"
    tools:context=".ChronoSwipeViewActivity"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

在主布局的include标记中

<include layout="@layout/activity_chrono_tab"
     android:layout_below="@id/toolbar"/>


将包含布局的根目录更改为
android:layout\u height=“wrap\u content”
,因为CoordinatorLayout在内部是FrameLayout。包含布局的match_parent属性覆盖在其顶部。当我尝试执行此操作时,出现一个错误,显示“未找到与给定名称匹配的资源(位于'layout_below'处,值为'@id/toolbar')。请确保您将其拼写为工具栏布局中上面的声明方式,但这应该可以工作。您可以尝试在这里添加
+
@+id/工具栏
,但您不需要这样做,这并不是最好的方法。也许也可以尝试清理你的项目。在进行xml更改时,这有时是必要的。如果这仍然不起作用,我可以试着看看你的xml文件。仍然不起作用。编辑问题以添加更多信息。此外,我添加的两个xml布局是唯一有问题的两个。很抱歉,您希望将
android:layout_below=“@id/toolbar”
添加到
标记,而不是包含文件的根。