RecyclerView会回收NestedScrollView中的项目吗?

kri*_*han 1 performance android android-layout android-recyclerview

我用两个RecyclerViewNestedScrollView。该设置的效果很好,但我担心它可能会对内存产生影响。我不确定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>
Run Code Online (Sandbox Code Playgroud)

A. *_*han 6

RecyclerView当它位于时,不会回收其项目NestedScrollView。实际上,当您setNestedScrollingEnabled(false)使用视图时,它将完全展开,并且滚动行为应由其父级提供,这是NestedScrollView您的情况。因此,如果您使用infinite RecyclerView,则当项目数增加时,内存和性能将降低。但是,只要您的项目数量不会影响内存和性能,那么RecyclerView内部使用就不会有NestedScrollView错。但是很明显,最好不要这样做。