I have a custom master detail flow that I would like to have the collapsing toolbar effect like you find in the default template. I don't understanding the nesting to get it to work.
My activity has two variants:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
tools:context="com.example.android.sunshine.app.MainActivity">
<!--
This layout is a two-pane layout for the Items master/detail flow.
-->
<fragment
android:id="@+id/fragment_main"
android:name="xyz.selfenrichment.robertotomas.three_two_one_rotate.MainFragment"
android:tag="@string/tag_gridview_one_column"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
tools:context="xyz.selfenrichment.robertotomas.three_two_one_rotate.MainFragment"
tools:layout="@layout/fragment_main" />
<FrameLayout
android:id="@+id/fragmentcontainer_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="@layout/fragment_detail" />
</LinearLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_main"
android:name="xyz.selfenrichment.robertotomas.three_two_one_rotate.MainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="@string/tag_gridview_two_columns"
tools:context="xyz.selfenrichment.robertotomas.three_two_one_rotate.MainFragment"
tools:layout="@android:layout/list_content" />
And my collapsing toolbar I believe should be like:
<android.support.design.widget.CoordinatorLayout ...
...
<android.support.design.widget.AppBarLayout ...
...
<android.support.design.widget.CollapsingToolbarLayout ...
...
<android.support.v7.widget.Toolbar
Now, I have to combine the two and add the layout behavior, like:
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="xyz.selfenrichment.robertotomas.popularmovies.PosterBoardActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
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/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
tools:context="com.example.android.sunshine.app.MainActivity"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!--
This layout is a two-pane layout for the Items master/detail flow.
-->
<fragment
android:id="@+id/fragment_main"
android:name="xyz.selfenrichment.robertotomas.popularmovies.MainFragment"
android:tag="@string/tag_gridview_one_column"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
tools:context="xyz.selfenrichment.robertotomas.popularmovies.MainFragment"
tools:layout="@layout/fragment_main" />
<FrameLayout
android:id="@+id/fragmentcontainer_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="@layout/fragment_detail" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_manage"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
But if I add the layout behavior to the fragment
tag, or to the underlying fragment xml (or to both):
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:stretchMode="columnWidth"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
Either way it doesn't matter, scrolling the gridview doesn't collapse the toolbar.
edit: This is particularly confusing since I see a pretty similar example here that apparently does work.
Woohoo :) I found it. I have the layout_behavior set, but then in the fragment class where I attach it to the data adapter I put these lines:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mGridView.setNestedScrollingEnabled(true);
}