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

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

以下xml是当前布局:

xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:id="@+id/linerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"


android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>


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

以下xml是改动后的布局:

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的效果

你可能感兴趣的:(NestedScrollView+RecyclerView 滑动卡顿简单解决方案)