recycleview 与其他视图同时滚动

Doe*_*oes 3 android scrollview android-recyclerview

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

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

我的 XML

 <Rel layout>
 <text-view id="text"/>
 <recycle-view below="text" />
Run Code Online (Sandbox Code Playgroud)

那么 textview 如何随着回收视图滚动上下移动可以为此提供小片段

ekc*_*ang 5

如果您真的想将 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>
Run Code Online (Sandbox Code Playgroud)

当您设置 RecyclerView 时,您可能想要调用,RecyclerView#setNestedScrollingEnabled(false)否则 RV 可能会消耗父级内部的一些滚动(您不想要)。

注意:这种方法需要权衡 RV 将被迫布局其所有视图,从而失去回收优势。正确的方法是正确地将 a 专用viewType于此标题 TextView 的 RV,而不是将其包装在其他 ViewGroup 中。