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>
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With