android - recyclerview 同时与其他 View 滚动

标签 android scrollview android-recyclerview

我有 recycleview,在顶部我有一个 View ,其中包括 textview。

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

我的 XML

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

所以 textview 将如何随着回收 View 滚动而上下移动可以为此提供小 fragment

最佳答案

如果你真的想将 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 将被迫布局其所有 View ,从而失去回收优势。正确的方法是适本地奉献一个 viewType到此 header TextView 的 RV,而不处理将其包装在其他 ViewGroup 中。

关于android - recyclerview 同时与其他 View 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37017528/

相关文章:

android - 想要将 TextView 添加到现有 layout.xml 中的 LinearLayout

android - TransitionManager 没有动画颜色变化

java - 在 recyclerView 中显示元素列表失败

android - 节省内部存储 android

android - 如何禁用主要 Activity 的方向更改?

android - Gradle 错误 : duplicate entry: com/android/volley/AuthFailureError. 类

Android - 计算器错误

android - 将 Intent 过滤器添加到 config.xml 中,以便在 AndroidManifest.xml (Ionic 2) 中正确插入

android - ListView 指示更多可滚动项目

android - RecyclerView 不能在 onBindViewHolder() 中使用 setText()