I was looking at Slidenerd's example code on github and I'm trying to modify it to suit my needs:
https://github.com/slidenerd/Android-Design-Support-Library-Demo
Now this is his original layout, except that I took out his tabLayout and inserted a textView:
The code for the layout in xml is below:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="slidenerd.vivz.navigationviewdemo.FourthActivity">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/root_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="192dp"
android:scaleType="centerCrop"
android:src="@drawable/rsz_bg_cover"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
android:text="Information"
android:textColor="#fff"
android:background="#000"
android:gravity="center"
android:padding="16dp"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/ic_add_black"
app:borderWidth="0dp"
app:fabSize="mini" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>
Now, I want the toolBar to be pinned to the top of the screen when I scroll my recyclerview (and I want my textView (the black rectangle with the white "Information" text to scroll out of view which is why I have given these flags to these elements:
Toolbar: app:layout_scrollFlags="scroll|exitUntilCollapsed"
TextView: app:layout_scrollFlags="scroll|enterAlways"
When I scroll however, the ToolBar pins itself correctly, but the TextView pins itself underneath the ToolBar.
How do I get it to scroll underneath the toolbar?
I do realise that it is possible to put the TextView as an object into the recyclerview adapter and scrolling it underneath the toolBar would occur naturally as I'm just scrolling the recyclerview.
I prefer not to take that route as I'm constantly adding / removing values / sorting the recyclerview and I do not want to have an empty object just so that I can get the textView on the top of the recyclerview as that increases the risk of NullPointerExceptions.