user_4685247
user_4685247

Reputation: 2985

Unexpected CoordinatorLayout behavior

This is the xml I'm using to create a collapsable toolbar animation:

The main layout:

   <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <android.support.design.widget.AppBarLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:fitsSystemWindows="true">
                <include layout="@layout/toolbar"/>
        </android.support.design.widget.AppBarLayout>
            <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </android.support.design.widget.CoordinatorLayout>

The toolbar layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    style="@style/AppTheme.toolbarStyle"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"/>

The layout that replaces the container FrameLayout:

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

The result I get:

enter image description here

Now the obvious problem is, that the Recyclerview is drawn below the toolbar, and the list starts scrolling only after the toolbar is completely hidden. The intended animation was to scroll the recyclerview at the same time as the toolbar is hidden. From what I've read it may be because the CoordinatorLayout is the subclass of FrameLayout. How do I fix it?

Upvotes: 1

Views: 338

Answers (1)

JanSLO
JanSLO

Reputation: 388

Add this to your FrameLayout (@+id/container):

app:layout_behavior="@string/appbar_scrolling_view_behavior"

Upvotes: 1

Related Questions