当给Toolbar
添加了滚动效果app:layout_scrollFlags="scroll|enterAlways"
之后,发现RecyclerView不能够流畅的滑动了,发现原来当RecyclerView
嵌套在NestedScrollView
里时,就会出现这种情况,我的大致布局如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="?android:colorBackground" android:theme="@style/AppTheme.DayNight" tools:context=".ui.main.MainActivity">
<android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/AppTheme.DayNight"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/content_main"/> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout>
|
修改
1 2
| recyclerView.setLayoutManager(layoutManager); + recyclerView.setNestedScrollingEnabled(false);
|
http://stackoverflow.com/questions/37782032/recycler-view-inside-nestedscrollview-with-coordinatorlayout