如何在图像上滚动内容?

How do I scroll content over an image?

我正在尝试实施 Play 商店 header 图片行为,但没有成功。 我能够滚动整个页面,但只能与 CollapsingToolbarLayout.
中的 ImageView 一起滚动 我用的是example at the announcement of Android Design Support library。 activity 的 XML 现在看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <android.support.design.widget.AppBarLayout
    android:layout_height="192dp"
    android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
    layout_width="wrap_content" layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <android.support.design.widget.CollapsingToolbarLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed" layout_width="wrap_content"
        layout_height="wrap_content">
        <ImageView

            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/imageView" android:layout_gravity="center_vertical" android:src="@android:mipmap/sym_def_app_icon"/>
        <android.support.v7.widget.Toolbar
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:layout_collapseMode="pin" layout_width="wrap_content" layout_height="wrap_content"/>

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
    <TextView android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="New Text"
              android:id="@+id/textView" android:layout_gravity="center_vertical"/>
</android.support.design.widget.CoordinatorLayout>

我很确定这里少了什么。

您需要将 AppBarLayout 包裹在 CoordinatorLayout 中,而不是使用 ScrollView

您还需要将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 放在 ViewGroup 上,紧跟在主页内容 AppBarLayout 之后。

Here's a layout from Chris Banes' cheesesquare sample app.