RecyclerView SCROLL_STATE_IDLE is being called lat

2019-05-21 04:34发布

问题:

On RecyclerView addOnScrollListener the property SCROLL_STATE_IDLE takes time to get called at end of the item size and when scrolled up to the top of the RecyclerView. But it works fine in middle of the scrolling.

The root view of the layout is CoordinatorLayout.

回答1:

Having the same issue, the only workaround I've found is to send a stopScroll() whenever the RecyclerView gets a SCROLL_STATE_SETTLING, though not the ideal solution. Probably would be better to detect if it has reached the top or bottom edge, taking into account the scrolling direction, and then call stopScroll():

@Override
public void onScrollStateChanged(final int state)
{
    super.onScrollStateChanged(state);

    if (state == RecyclerView.SCROLL_STATE_SETTLING)
    {
        this.stopScroll();
    }
}

Update

This issue seems to be a bug in the support library, though it was reported as fixed its clear that the problem still exists, so hopefully we should see an adequate solution in the future:

https://issuetracker.google.com/issues/66996774



回答2:

Invoke stopScroll() when your recyclerview has been reached to to bottom. I think Since it's support library version up, velocity is calulated and it makes delay a little.