约束布局重叠工具栏

Constraint layout Overlapping Toolbar

我的布局有问题。我正在尝试将约束布局放置在工具栏下方。但是,它决定要与工具栏重叠。我试过使用 app:layout_behavior="@string/appbar_scrolling_view_behavior" 但没有成功。

工具栏正在另一个 xml 文件中创建并使用 include 调用。

Activity低于

<android.support.v4.widget.DrawerLayout

    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:id="@+id/drawer_layout"
    android:fitsSystemWindows="true"
    tools:context="XXXXXX"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

<include
    android:id="@+id/test1234"
    layout="@layout/app_bar_home"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header"
    app:menu="@menu/drawer_menu" />

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintTop_toBottomOf="@id/test1234">

**Bunch of constraints here etc**

**Bunch of buttons here**

</android.support.constraint.ConstraintLayout>


</android.support.v4.widget.DrawerLayout>

Here is an image of what it looks like

What it should look like

编辑

在 android 工作室的设计视图中显示就可以了。然而,当在 phone 或模拟器上打开时,它仍然是坏的。

应用程序在模拟时看起来仍然像第二张图片。

With the fixes below

我遇到了同样的问题然后我用这个解决了它。 在你的约束布局中,写这个

     android:layout_marginTop="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior

您是在将此属性暗示给父标签。您必须将此添加到 ConstraintLayout 或抽屉布局的主要内容。