首页 > 解决方案 > 约束布局重叠工具栏

问题描述

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

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

下面的活动

<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>

这是它的样子

它应该是什么样子

编辑

在 android studio 的设计视图中显示时很好。但是,当在手机或模拟器上打开时,它仍然坏了。

模拟时,应用程序仍然看起来像第二个图像。

通过以下修复

标签: androidandroid-constraintlayoutdrawerlayout

解决方案


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

     android:layout_marginTop="?attr/actionBarSize"

推荐阅读