Recycler view放在NestedScrollView内部时,Toolbar的滚动效果无效

当给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

文章作者: 二十I邊界
文章链接: https://xuie0000.com/post/2016-12-23-2019/Recycler-view放在NestedScrollView内部时,Toolbar的滚动效果无效.html
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 二十I邊界