When you you click on a movie in Google Play and go to landscape mode, the image is in the background and the details of a movie is on a layout above the background. These 2 surfaces scroll together. How can I do that?
Movie Section Google Play Movie Example
I have collapsing toolbar (the background image is here) and I tried anchoring the entire nested scrollview to the app bar. But that doesn't work.
<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">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:expandedTitleMargin="16dp">
<ImageView
android:id="@+id/iv_movie_detail_backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<View
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_gravity="bottom"
android:background="@drawable/scrim"/>
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include
layout="@layout/scrollview_movie_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
The ImageView
should have the usual flag (parallax
) : app:layout_collapseMode="parallax"
and it should be in the CollapsingToolbarLayout
.
About the content you see, just add:
app:behavior_overlapTop="100dp" // 100dp for example
To your NestedScrollView
(or anything like RecyclerView
which has: app:layout_behavior="@string/appbar_scrolling_view_behavior"
).
There is a good sample in here which you can use: https://github.com/saulmm/CoordinatorBehaviorExample