您的位置:首页 > 其它

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

2017-12-15 21:00 2256 查看

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

以下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的效果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐