AppBarLayout 重叠 ConstraintLayout。

13

我在CoordinatorLayout中嵌套了一个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"
    tools:context="com.example.michael.blemanager.Activities.ColorPickerActivity.Color1">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        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/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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

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

这是包含的布局content_color1

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.michael.blemanager.Activities.ColorPickerActivity.Color1"
    tools:showIn="@layout/activity_color1">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/default_background"
        >

        /....

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

现在由于某些原因,AppBarLayoutConstraintLayout 相互重叠。

看到工具栏重叠在颜色圆圈上了吗?我该如何避免这种重叠?

图片描述

2个回答

8

将您的包含标签放在FrameLayout中,使用appbar_scrolling_view_behaviorlayout_behavior进行包装,如下所示:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <include layout="@layout/content_color1"/>
</FrameLayout>

-2

将CoordinatorLayout更改为ConstraintLayout。

我遇到了同样的问题,这对我有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接