美文网首页Android开发收藏夹Android札记
NestedScrollView+RecyclerView 滑动

NestedScrollView+RecyclerView 滑动

作者: jzhu085 | 来源:发表于2016-08-24 10:55 被阅读9305次

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

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

    相关文章

      网友评论

      • 怜悯是我的座右铭:这样做没有fling效果
      • Ven_X:不知在NestedScrollView 里面嵌套了RecyclerView 之后,RecyclerView禁止自身滑动,这样的RecyclerView还有复用吗?
      • a46a512e94c9:android:nestedScrollingEnabled="false" 以后确实是可以解决惯性问题 但是RecyclerView却不能上下拖动了。。
        jzhu085:@唉哟哎 依赖外部滚动啊
        a46a512e94c9:问题解决了 我是 NestedScrollView 嵌套 ViewPager ,ViewPager嵌套RecyclerView 最后重写ViewPager 后完美解决 参考地址 http://www.jianshu.com/p/28e4346a41cf
      • 7e722526bb04:你这样处理,recyclerview不就不能上拉加载更多了吗???
        599ab633e8f4:@老实巴交的读书人 recyclerview没有滚动监听了呗.
        jzhu085:@7e722526bb04 为啥不行?
      • Fritz_Xu:这个确实可以解决方法,但是NestedScrollView这个fling真的太快了,瞬间就到底了
        jzhu085:@武械 VelocityTracker
        Fritz_Xu:@老实巴交的读书人 有改变fling速度的方法?
        jzhu085:@武械 fling可以自己处理呀

      本文标题:NestedScrollView+RecyclerView 滑动

      本文链接:https://www.haomeiwen.com/subject/zwnnsttx.html