Achieve the same behavior as AppBarLayout for any ViewGroup in CoordinatorLayout

I have the following problem with custom views in CoordinatorLayout: I need to collapse ViewGroup (fe LinearLayout) when scrolling through RecyclerView. ViewGroup acts as the header of the RecyclerView. When using the following code:

<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent"> <LinearLayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|enterAlways" android:orientation="vertical"> <!-- TextViews, etc. --> </LinearLayout> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.design.widget.CoordinatorLayout> 

This does not work even if I tried to add the app: layout_bevahiour property with the appropriate value for the recycler header. RecyclerView will occupy the entire screen and the title (LinearLayout) will not be displayed. But when I change LinearLayout to AppBarLayout, everything works like a charm, but the title is styled as an action bar.

Is there any way to achieve the same behavior as AppBarLayout for any ViewGroup (fe LinearLayout)?

+5
source share

Source: https://habr.com/ru/post/1233162/


All Articles