Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recycler View loading very slow for large data when inside NestedScrollView

I have added RecyclerView inside my NestedScrollView. Basically I want RecyclerView to scroll with other Views. The problem that I am facing is that for a small set of data, it is working fine, but for a large set of data(200 entries) whenever I launch the activity, it freezes for about about 3-5 seconds and then loads. I removed the NestedScrollView and it is working flawlessly, but it doesn't provide me the behaviour I want.

(For extra info, I am loading the data from SQLite database. There is no problem in scrolling, as it is smooth. The only problem is the activity is freezing 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>
like image 255
Gurleen Sethi Avatar asked Jun 16 '17 04:06

Gurleen Sethi


People also ask

How do I use NestedScrollView with ConstraintLayout and RecyclerView?

Just add the fillViewPort parameter to your NestedScrollView . Like that the ConstraintLayout will expand just as you'd set its width to match_parent and the RecyclerView will dynamically expand its size.

What is nested scrolling in RecyclerView?

A android.view.ViewGroup that shows items in a horizontal scrolling list. NestedScrollView. NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android.

Which RecyclerView method is called when getting the size of the data set?

getItemCount() : RecyclerView calls this method to get the size of the data set. For example, in an address book app, this might be the total number of addresses. RecyclerView uses this to determine when there are no more items that can be displayed.


1 Answers

This case of RecyclerView inside NestedScrollView.

RecyclerView is calling onCreateViewHolder() times equal to your data size.

If data has 200 items, it freezes for onCreateViewHolder() to be called 200 times.

like image 113
배준모 Avatar answered Sep 20 '22 17:09

배준모