Recycler View loading is very slow for big data when inside NestedScrollView

I added a RecyclerView inside my NestedScrollView . I basically want the RecyclerView to scroll along with other views. The problem I ran into is that it works fine for a small data set, but for a large data set (200 records), whenever I start an activity, it freezes for about 3-5 seconds and then loads. I uninstalled NestedScrollView and it works flawlessly, but it does not give me the behavior I want.

(For more information, I'm loading data from an SQLite database. There is no problem scrolling because it is smooth. The only problem is that the activity freezes for a while)

 <android.support.v4.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"> <... Some other Views ...> <android.support.v7.widget.RecyclerView android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical"> </android.support.v7.widget.RecyclerView> </LinearLayout> </android.support.v4.widget.NestedScrollView> 
+5
source share
2 answers

This case is a RecyclerView inside a NestedScrollView .

RecyclerView calls onCreateViewHolder() times equal to your data size.

If the data has 200 elements, it hangs for onCreateViewHolder() , which is called 200 times.

+5
source

As Nancy says, recyclerview.setNestedScrollingEnabled (false); will solve the scroll problem. I also ran into this type of problem and solved the false NestedScroll.

-2
source

Source: https://habr.com/ru/post/1268894/


All Articles