【发布时间】:2015-12-04 14:18:23
【问题描述】:
我希望将滚动支持添加到CoordinatorLayout 的单个可滚动子视图以及AppBarLayout 和CollapsingToolbarLayout 中。滚动RecyclerView 或AppBarLayout(下面的压缩代码)时,应用栏及其内容成功滚动和折叠。但是,当尝试在RecyclerView 上方的LinearLayout 上启动滚动事件时,没有任何反应,因为LinearLayout 不知道滚动或折叠视图。
目标是让LinearLayout 充当RecyclerView 的粘性页眉和AppBarLayout 的页脚,并接收与RecyclerView 相同的滚动行为,类似于Spotify's shuffle play/available offline header。事实上,如果appbar_scrolling_view_behavior layout_behavior 可以像RecyclerView 一样应用于LinearLayout,那就太好了,但我想这种行为在不可滚动的视图上会被忽略。是否有人知道不需要将LinearLayout 视图作为RecyclerView 中的一行来实现的解决方法?
<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.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/collapsible_app_bar_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient_banner"
app:contentScrim="@color/background_content_frame"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/image_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/some_image"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/collapsible_toolbar"
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>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/slide_handle_height"
android:orientation="horizontal"
android:background="@color/slide_handle"
android:gravity="center_vertical">
<!-- three buttons -->
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/slide_handle_height"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
-
也许不可能,因为 Spotify 不使用设计支持库,但我不知道
-
@MarioVelasco 正确,Spotify 不使用 CollapsingToolbarLayout 实现,但我引用它作为我希望通过某种解决方法实现的行为的示例。
-
好消息!我有一个真正的解决方案给你。这将解决您尝试执行的操作,查看一下,如果您喜欢,请标记为已解决。
标签: android androiddesignsupport android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout