约束布局重叠工具栏

问题描述 投票:0回答:2

我有布局问题。我试图让约束布局放在工具栏下面。但是,它决定要重叠工具栏。我尝试过使用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>

Here is an image of what it looks like

What it should look like

编辑

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

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

With the fixes below

android android-constraintlayout drawerlayout
2个回答
0
投票

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

     android:layout_marginTop="?attr/actionBarSize"

0
投票
app:layout_behavior="@string/appbar_scrolling_view_behavior

您将此属性隐含在父标记中。您必须将此添加到ConstraintLayout或抽屉布局的主要内容。

© www.soinside.com 2019 - 2024. All rights reserved.