我在 NestedScrollView
中使用了两个 RecyclerView
。该设置运行良好,但我担心它可能产生的内存影响。我不确定 RecylerView 是否会像它那样回收组件。这还有其他缺点吗?
这是一些代码:
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_coordinator_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="54dp"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:id="@+id/toplayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleview2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/recycleview1"
android:nestedScrollingEnabled="false"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
最佳答案
RecyclerView
在 NestedScrollView
内时不会回收其项目。事实上,当您为 View 设置 setNestedScrollingEnabled(false)
时,它将完全展开并且滚动行为应由其父级提供,在您的情况下为 NestedScrollView
。因此,如果您有一个无限的 RecyclerView
,那么当项目数量增加时,内存和性能将会降低。但只要您的项目数量不会影响内存和性能,在 NestedScrollView
中使用 RecyclerView
就不是坏事或错误。但很明显,最好不要那样做。
关于android - RecyclerView 会回收 NestedScrollView 中的项目吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45657409/