Android toolbar does not expand when scrolling up

I have a toolbar that crashes when the RecyclerView scrolls down, but when the user scrolls quickly, the toolbar does not expand. Any idea what is wrong?

This behavior is shown in this video: https://youtu.be/67ntPkW-5XA

Layout Code:

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/coordinator_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="192dp" android:fitsSystemWindows="true" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|bottom" android:layout_margin="16dp" android:clickable="true" android:onClick="showText" android:src="@drawable/ic_done_white_24dp" app:borderWidth="0dp" /> 

+5
source share
1 answer

If you want it to expand each time you scroll up, you must add app:layout_scrollFlags="scroll|enterAlways" to the view you want to display.

As I understand it, you want to add this to your CollapsingToolbarLayout .

Possible flags:

scroll : this flag should be set for all views that need to be scrolled from the screen - for views that do not use this flag, they will remain attached to the top of the screen

enterAlways : this flag ensures that any downward scroll will make this view visible, allowing a "quick return pattern

enterAlwaysCollapsed : When your view has declared minHeight, and you use this flag, your view will only be entered at the minimum height (ie, โ€œcollapsedโ€), only expanding to full height when it reaches the top of the scroll bar.

exitUntilCollapsed : this flag causes the view to scroll until it crashes (its minHeight) before exiting

+2
source

All Articles