Reputation: 3502
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>
Upvotes: 14
Views: 11897
Reputation: 1732
Yes, the answer is a bit late, but I think this will prevent you from freezing your RecyclerView inside any kind of Scrollable Views like another RecyclerView, ScrollView, NestedScrollView, MotionView, etc...
All you have to do is give your RecyclerView a fixed height.
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_home"
android:layout_width="match_parent"
android:layout_height="192dp"/>
Upvotes: 0
Reputation: 1
I faced the same problem! The solution was to change NestedScrollView to SwipeRefreshLayout.
add this for enable/disable ToolBar Scrolling:
ViewCompat.setNestedScrollingEnabled(recyclerView, true);
Upvotes: 0
Reputation: 151
The problem as said above is because RecyclerView as a child or subChild in NestedScrollView measures its height as infinitive when you use WRAP_CONTENT or MATCH_PARENT for height of RecyclerView.
one solution that solved this problem for me was setting the RecyclerView Height to a fixed size. you could set height to a dp value, or you could set it to a pixel value matching devices height if your requirements needs a vertical infinitive RecyclerView.
here is a snippet for setting the recyclerView size in kotlin
val params = recyclerView.layoutParams
params.apply {
width = context.resources.displayMetrics.widthPixels
height = context.resources.displayMetrics.heightPixels
}
recyclerView.layoutParams = params
Upvotes: 0
Reputation: 601
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.
Upvotes: 19
Reputation: 143
As said by Nancy , recyclerview.setNestedScrollingEnabled(false); will solve scroll stuck issue. i too faced this type of issue and solved by false the NestedScroll.
Upvotes: -5