我有 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/