0

I have a RecyclerView inside a NestedScrollView. It's working fine when recyclerView adapter list size is small. But when list size is large , it's crashing my app (or make more lag). How can i fix it. Codes are below.

XML :

   <androidx.core.widget.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">

                 <com.google.android.material.textview.MaterialTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginRight="20dp"
                    android:text="0 Products"
                    android:textSize="16sp"
                    android:theme="@style/radio_font_textview" />

              <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/products_recycler"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:layout_marginTop="15dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>


            </LinearLayout>
        </androidx.core.widget.NestedScrollView>

JAVA :

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ProductView.this);
productRecyclerAdapter = new ProductViewRecyclerAdapter(mData,mData2,ProductView.this);
products_recycler.setAdapter(productRecyclerAdapter);
ViewCompat.setNestedScrollingEnabled(products_recycler, false);
products_recycler.setLayoutManager(linearLayoutManager);
  • Please [edit] your question to put proper casing. All caps is considered shouting. – Mat Feb 09 '20 at 17:40

1 Answers1

1

Recycler view is built to solve memory related issues and increase performance, because it recycles the off-screen view holders and easily handle large no of items.

But when you put a RecyclerView inside NestedScrollView it loses its ability to recycle ViewHolders and hence causes issues when large amount of data is loaded into its adapter.

So either decrease the size/length of items that you're loading into recycler or provide your proper use case and crash stack trace, So that we can suggest a proper solution

Harsh Jatinder
  • 726
  • 6
  • 12