android - RecyclerView 会回收 NestedScrollView 中的项目吗?

标签 android performance android-layout android-recyclerview

我在 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>

最佳答案

RecyclerViewNestedScrollView 内时不会回收其项目。事实上,当您为 View 设置 setNestedScrollingEnabled(false) 时,它将完全展开并且滚动行为应由其父级提供,在您的情况下为 NestedScrollView。因此,如果您有一个无限的 RecyclerView,那么当项目数量增加时,内存和性能将会降低。但只要您的项目数量不会影响内存和性能,在 NestedScrollView 中使用 RecyclerView 就不是坏事或错误。但很明显,最好不要那样做。

关于android - RecyclerView 会回收 NestedScrollView 中的项目吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45657409/

相关文章:

java - 从android发送数据到mysql数据库

java - 使用 RecyclerView.Adapter 过滤大量条目

android - 在 Android 应用程序中使用 Intent 来显示另一个 Activity

performance - 填充非常大的哈希表-如何最有效地做到这一点?

android - 如何获得一个文本可以增长和椭圆化的布局,但不会吞噬布局上的其他元素

具有自定义项目复杂布局的 Android ExpandableListView

android - 我们如何增加 toast 的字体大小?

android - SearchView 未向结果 Activity 发送 Intent

Java - 收集过去值的最佳方法

ios - 考虑到性能,如何在 UICollectionViewCell 中旋转 UILabel?