How to use RecyclerView
inside NestedScrollView
?
RecyclerView
content is not visible after setting adapter.
UPDATE layout code updated.
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/keyline_1">
</RelativeLayout>
<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e5e5e5" />
<android.support.v7.widget.RecyclerView
android:id="@+id/conversation"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
This is what working for me
Here is the code that I'm using to avoid scrolling issues:
There is a simple and testing code u may check
I had to implement CoordinatorLayout with toolbar scrolling and it just took me all the day messing around this. I've got it working by removing NestedScrollView at all. So I'm just using RelativeLayout at the root.
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.
1) You need to use support library 23.2.0 (or) above
2) and
RecyclerView
height will bewrap_content
.3)
recyclerView.setNestedScrollingEnabled(false)
But by doing this the recycler pattern don't work. (i.e all the views will be loaded at once because
wrap_content
needs the height of completeRecyclerView
so it will draw all childView
s at once. No view will be recycled). Try not to use this pattern util unless it is really required. Try to useviewType
and add all other views that needs to scroll toRecyclerView
rather than usingRecyclerView
inScrollview
. The performance impact will be very high.To make it simple "it just acts as
LinearLayout
with all the child views"