【发布时间】:2016-08-18 16:37:37
【问题描述】:
我有回收站视图。在位置 0,我已经制作了标题,其余的项目将从位置 1 来。这是我的布局
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:background="@color/listview"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
我想要当我滚动我的回收器视图时,当一半的标题向上滚动时,剩余的标题会粘在顶部,而回收器视图的其他项目也会滚动。并且在某个点之后,标题的粘性部分也会向上移动。如何实现它。
【问题讨论】:
-
如果需要那个动态的,我会诚实地处理回收器视图之外的标题视图;标题在概念上并不难,但让一个像这样滑入和滑出一半似乎是一个真正的挑战。
-
你将如何处理回收站视图之外的标题视图,以便标题仅向上滚动一半然后粘住。
-
你可以尝试做一些事情,比如让 RecyclerView 正常滚动,但是检测第一个项目何时退出一半,一旦出现,就有一个覆盖视图反映第一个项目被推到一半屏幕。这将产生第一个项目作为标题停止在顶部的错觉,而实际上它正在与适配器的其余部分一起滚动。当第一个项目返回视图时检查向下滚动并处理标题视图的可见性。就在我的脑海中,这并不是最好的解决方案。
-
正如下面提供的答案所说,还有 ItemDecorator 选项,但我认为它不允许滚动,我认为它管理一个位于静态位置的标题在列表的顶部。
标签: android android-recyclerview