RecyclerView和NestedScrollView嵌套

1.为了更好的适应NestedScrollView的特性,应该把布局文件的根布局设为CoordinatorLayout;

2.给NestedScrollView设置behavior,即 app:layout_behavior="@string/appbar_scrolling_view_behavior"

3.RecyclerView的高度设为match parent或者wrap content

这样就可以保证RecyclerView的内容可以显示出来,但是为了解决滑动不流畅的问题,还需要最后一步:

4. recyclerView.setNestedScrollingEnabled(false);

   如果 是在布局文件中使用可以参考如下:

 
<android.support.v4.widget.NestedScrollView
    android:id="@+id/f_scroll_sub"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/mlaycourse"
    android:fadingEdge="none"
    android:scrollbars="none">
<android.support.v7.widget.RecyclerView android :id= "@+id/mRecycleorCourse" android :layout_width= "match_parent" android :layout_height= "wrap_content" android :nestedScrollingEnabled= "false" app :layout_behavior= "@string/appbar_scrolling_view_behavior" /> </android.support.v4.widget.NestedScrollView>

这样就可以实现了


猜你喜欢

转载自blog.csdn.net/qq_21434809/article/details/80760459