我刚升级到API 26和支持库26.0.2。但是发现我的RecyclerView
在滚动后右侧的条目不能立即点击,需要等待一秒钟左右才行。即使RecyclerView
没有滚动(例如已经滑动到顶部),也是如此。
当我降级到支持库25.4.0时,一切都恢复正常了。
关键是我的RecyclerView
在一个CoordinatorLayout
中,并且在AppBarLayout
的Toolbar
上有一个SCROLL_FLAG_SCROLL
标志。如果我不使用这个标志,那么这个问题将消失。所以我认为这是支持库26的一个隐藏行为更改。
我尝试向CoordinatorLayout
添加focusable="false"
,但仍然没能解决问题。
是否有办法禁用此行为?因为需要双击才能触发单击事件真的很烦人。
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinateLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/fragmentAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:background="@null">
<include
android:id="@+id/dynamicActionBarHolder"
layout="@layout/dynamic_action_bar"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/pullToRefreshMailRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/mailRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
编辑
我认为问题在于RecyclerView
的scrollState
。当它停止滚动时,它不会立刻更改为SCROLL_STATE_IDLE
。查看RecyclerView
的源代码,我发现有一个ViewFlinger
控制滚动状态。当我向下快速滑动到顶部时,它不会立即调用setScrollState(SCROLL_STATE_IDLE)
,而是等待一段时间才触发此方法。我滑动得越快,等待的时间就越长。就像RecyclerView
仍在后台滚动一样。因为当RecyclerView
接触顶部停止滚动时,scroller.isFinished()
并不会立即返回true。也许这是RecyclerView
在CoordinatorLayout
中的一个bug。
SwipeRefreshLayout
中的app:layout_behavior
并再试一次吗? - Aytek SökmensetScrollFlags(0)
。 - Kimi Chiu