android - CoordinatorLayout with RecyclerView And Collapsing header -


i have layout following:

enter image description here

(toolbar, header view, text view, recyclerview)

i need header collapsed when scrolling recyclerview's items. view "choose item" , recyclerview left on screen.

i saw examples when toolbar being collapsed, need toolbar present always.

which layouts/behavior should use work?

you can achieve having layout:

<android.support.design.widget.coordinatorlayout     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="match_parent">      <android.support.design.widget.appbarlayout         android:layout_width="match_parent"         android:layout_height="wrap_content">          <android.support.design.widget.collapsingtoolbarlayout             android:layout_width="match_parent"             android:layout_height="match_parent"             app:layout_scrollflags="scroll|exituntilcollapsed">              <!-- header -->             <relativelayout                 ...                 app:layout_collapsemode="parallax">                 .....             </relativelayout>              <android.support.v7.widget.toolbar                 android:layout_width="match_parent"                 android:layout_height="?attr/actionbarsize"                 app:layout_collapsemode="pin" />          </android.support.design.widget.collapsingtoolbarlayout>         <!-- if want keep "choose item" on top of recyclerview, put textview here         <textview              android:layout_width="match_parent"              android:layout_height="wrap_content"              android:layout_gravity="bottom"              android:text="choose item" />        -->     </android.support.design.widget.appbarlayout>      <android.support.v7.widget.recyclerview         android:layout_width="match_parent"         android:layout_height="match_parent"         app:layout_behavior="@string/appbar_scrolling_view_behavior" />  </android.support.design.widget.coordinatorlayout> 

you pin toolbar having app:layout_collapsemode="pin" property set. make recyclerview scrollable setting app:layout_behavior="@string/appbar_scrolling_view_behavior" , that's pretty it.

nb! position of "choose item" textview depends on particular behaviour want achieve:

  • you can include first element of recyclerview's adapter scroll away, once user start scrolling through recyclerview;
  • you can add appbarlayout stick on top of recyclerview, whenever scroll or not;

you can read more here android design support library , here design support library (iii): coordinator layout

i hope, helps!


Comments