How to use RecyclerView
inside NestedScrollView
?
RecyclerView
content is not visible after setting adapter.
UPDATE
If you are using RecyclerView ScrollListener inside NestedScrollView, addOnScrollListener listener not working properly if you are used both.
Use this code.
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
......
}
});
this code working fine RecyclerView ScrollListener inside NestedScrollView.
thanks
I have Viewpager and RecyclerView inside the NestedScrollView. After adding below lines
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setHasFixedSize(false);
I solved slow scroll and scroll lag issue.
nestedScrollView.setNestedScrollingEnabled(true);
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
//...
}
});
<androidx.core.widget.NestedScrollView
android:id="@+id/nested"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_below="@id/appBarLayout_orders"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.constraintlayout.widget.ConstraintLayout ...
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
Replace your recyclerView with,
<android.support.v7.widget.RecyclerView
android:id="@+id/conversation"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
here,
app:layout_behavior="@string/appbar_scrolling_view_behavior"
will manage the rest of things.
One more thing, no need to put your recyclerView inside NestedScrollView
One solution to keep the recycling feature of the recyclerview and avoiding the recyclerview to load all your data is setting a fix height in the recyclerview itself. By doing this the recyclerview is limited only to load as much as its height can show the user thus recycling its element if ever you scroll to the bottom/top.
if you want to use RecyclerView in NestedScrollView this is a simple tricky, just set :
RecyclerView
recyclerView.setHasFixedSize(false) (java/kt)
android:nestedScrollingEnabled="false"
android:layout_height="wrap_content"
android:overScrollMode="never"
NestedScrollView
this is work for me, and you can use many RecyclerView in NestedScrollView with this too.