recycleview同时滚动其他视图



我有recycleview,在顶部我有一个包含textview的视图。

我的问题是,当向上滚动时,文本视图总是在顶部,而只有循环视图滚动。。是任何我可以滚动两者的方式。我不想在回收视图中使用视图类型,因为它已经用于其他目的

我的XML

 <Rel layout>
 <text-view id="text"/>
 <recycle-view below="text" />

因此,文本视图如何随着循环视图滚动而上下移动,可以为这个提供一个小片段

如果您真的想将TextView与RecyclerView分开,请将它们封装在NestedScrollView中:

<NestedScrollView
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
      <TextView />
      <RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
  </LinearLayout>
</NestedScrollView>

当您设置RecyclerView时,您可能需要调用RecyclerView#setNestedScrollingEnabled(false),否则RV可能会在父级中消耗一些滚动(这是您不希望的)。

注意:这种方法进行了权衡,即RV将被迫布局其所有视图,从而失去回收效益。正确的方法是将viewType适当地专用于此标头TextView的RV,而不是将其封装在其他ViewGroups中。

最新更新