I just upgraded to API 26 and support library 26.0.2. But I found that my RecyclerView
items is not clickable right after the scrolling. If you wait for a second, it will work. But if you click the item immediately, it won't. Even if the RecyclerView
is not scrolling at all(e.g. has scrolled to the top).
When I downgraded to support library 25.4.0 everything goes fine again.
The key point is that my RecyclerView
is in a CoordinatorLayout
and has a SCROLL_FLAG_SCROLL
flag on my Toolbar
of the AppBarLayout
. If I don't use this flag, then this problem will disappear. So I think it's a hidden behavior change of support library 26.
I've tried to add focusable="false"
to the CoordinatorLayout
but still had no luck.
Is there any way to disable this behavior? Because it's really annoying to click twice to trigger the click event.
<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>
EDIT
I think the problem is the scrollState
of the RecyclerView
. When it's stopped scrolling, it's not changed to SCROLL_STATE_IDLE
immediately. Looking into the source code of RecyclerView
, I found there's a ViewFlinger
controlling the scroll state. When I fling down to scroll to the top, it's not calling setScrollState(SCROLL_STATE_IDLE)
immediately, instead, it wait for a while to trigger this method. The more fast I fling, the more time I need to wait. It just like the RecyclerView is still scrolling in the background. Because the scroller.isFinished()
doesn't return true right after the RecyclerView
stop scrolling when it touched the top. Maybe it's a bug of the RecyclerView
when it's in a CoordinatorLayout
.