Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will RecyclerView recycle items inside NestedScrollView?

I am using two RecyclerView inside a NestedScrollView. The setup works great but I am worried about the memory impacts that it can have. I am not sure Whether the RecylerView will recycle components like it does. Are there any other downsides for this?

Here is some code:

<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>
like image 861
krishan Avatar asked May 16 '26 03:05

krishan


1 Answers

RecyclerView does not recycle its items when it is inside a NestedScrollView. In fact, when you setNestedScrollingEnabled(false) for a view, it will be expanded fully and scrolling behavior should provide by its parent, which is a NestedScrollView in your case. So, if you have an infinite RecyclerView, then the memory and performance will be reduced when number of items increases. But as long as number of your items is not so much that can impact the memory and performance, using RecyclerView inside NestedScrollView is not bad or wrong. But it is obvious that it's better not to do that.

like image 174
A. Badakhshan Avatar answered May 17 '26 19:05

A. Badakhshan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!