手动滚动RecyclerView不会更新CoordinatorLayout,而通过触摸滚动它会更新CoordinatorLayout [英] Scrolling RecyclerView manually does not update CoordinatorLayout , while scrolling by touch it update CoordinatorLayout

查看:107
本文介绍了手动滚动RecyclerView不会更新CoordinatorLayout,而通过触摸滚动它会更新CoordinatorLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

     <! -- Your Scrollable View -->
    <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
   <android.support.v7.widget.Toolbar
                  ...
                  app:layout_scrollFlags="scroll|enterAlways">

        <android.support.design.widget.TabLayout
                  ...
                  app:layout_scrollFlags="scroll|enterAlways">
     </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

当我通过触摸(在屏幕上)对recyclerview进行排序时,滚动行为将按预期方式工作,但是当我以编程方式滚动recyclerview时

when i scoll the recyclerview by touch ( on screen) the scroll behaviour works as expected , but when i scroll the recyclerview programmatically

LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager());
        layoutManager.scrollToPositionWithOffset(spanCount * exactItemPos / mScrollPosState.rowHeight,
                -(exactItemPos % mScrollPosState.rowHeight));

recyclerview滚动工具栏不

the recyclerview scrolls toolbar does not

推荐答案

CoordinatorLayout.Behaviour仅适用于NestedScroll事件.当您尝试以编程方式滚动RecyclerView时,将其视为普通滚动.

CoordinatorLayout.Behaviour is works with only NestedScroll event. When you try to scroll RecyclerView programmatically it is treat as normal scroll.

在下面的行中编写以通知RecyclerView启动NesteadScroll,并使用 ViewCompat.SCROLL_AXIS_VERTICAL ViewCompat.TYPE_NON_TOUCH

Write below line to inform RecyclerView start NesteadScroll, With ViewCompat.SCROLL_AXIS_VERTICAL and ViewCompat.TYPE_NON_TOUCH

ViewCompat.SCROLL_AXIS_VERTICAL::指示沿垂直轴滚动. ViewCompat.TYPE_NON_TOUCH::指示手势的输入类型是由用户非触摸屏幕引起的.这通常是由于扑杀而来.

ViewCompat.SCROLL_AXIS_VERTICAL: Indicates scrolling along the vertical axis. ViewCompat.TYPE_NON_TOUCH: Indicates that the input type for the gesture is caused by something which is not a user touching a screen. This is usually from a fling which is settling.

recycler_view.startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL, ViewCompat.TYPE_NON_TOUCH)
recycler_view.smoothScrollBy(0,200)

这篇关于手动滚动RecyclerView不会更新CoordinatorLayout,而通过触摸滚动它会更新CoordinatorLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆