Is there a way to collapse another view above RecyclerView when scrolling RecyclerView ? I know how to do this with the Toolbar , but something is not clear how to do the same with other views?

    2 answers 2

    Here is a sample code. You need to put your View in AppBarLayout . Here, layoutHeader will scroll when scrolling RecyclerView .

     <?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" android:id="@+id/coordinatorLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> </android.support.v7.widget.RecyclerView> <android.support.design.widget.AppBarLayout android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/layoutHeader" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/mkbPrimaryColor" android:orientation="vertical" android:visibility="visible" app:layout_scrollFlags="scroll|enterAlways"> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout> 

    Notice the additional app:layout_behavior="@string/appbar_scrolling_view_behavior" attributes app:layout_behavior="@string/appbar_scrolling_view_behavior" and app:layout_scrollFlags="scroll|enterAlways"

    AppBarLayout recommended to be placed below the rest of the elements. However, it will still be at the top of the page.

    • Thank! Exactly what is needed. - Spelcrawler

    If I understand you correctly, then you need to use the Quick return pattern

    • Thank you, but not really. I need the top view not to be part of the RecyclerView . I want to smash them across CardView - Spelcrawler