NestedScrollView+RecyclerView 滑动卡顿简单解决方案

这个是在工作中发现的问题

以下xml是当前布局:
<code>
<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:id=”@+id/linerLayout”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”

<android.support.v7.widget.RecyclerView
android:id=”@+id/recyclerView”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</code>

NestedScrollView中包含了LinearLayout,LinearLayout包含了一系列的组件,其中包括RecyclerView,RecyclerView和NestedScrollView都有滚动事件,这种情况下进行滑动操作,fling的操作体验很差,几乎就是手指离开的时候,滑动停止.

以下xml是改动后的布局:
<android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" android:nestedScrollingEnabled="false" />
android:nestedScrollingEnabled=”false”
官方文档:
Enable or disable nested scrolling for this view.
If this property is set to true the view will be permitted to initiate nested scrolling operations with a compatible parent view in the current hierarchy. If this view does not implement nested scrolling this will have no effect. Disabling nested scrolling while a nested scroll is in progress has the effect of stopping the nested scroll.
这里设置为false,放弃自己的滑动,交给外部的NestedScrollView处理,就没有出现卡顿的现象了,并且有fling的效果

    原文作者:老实巴交的读书人
    原文地址: https://www.jianshu.com/p/1edf795fce75
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞