Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppBarLayout overlaps ConstraintLayout

Tags:

android

I have an AppBarLayout nested inside of a CoordinatorLayout

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

Here is the included layout 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>

Now for some reason the AppBarLayout overlaps the ConstraintLayout

See where the tool bar overlaps the color circle? How do I prevent the overlap?

enter image description here

like image 561
the_prole Avatar asked Jun 02 '17 00:06

the_prole


1 Answers

Wrap your include tag inside a FrameLayout using layout_behavior of appbar_scrolling_view_behavior like this:

<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>
like image 147
João Carlos Avatar answered Sep 19 '22 06:09

João Carlos