Doesn't seem like a problem, right?) Let me explain a usage example. Let at the end of each scroll event you want to animate / highlight the target object:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener(){ @Override public void onScrollStateChanged(final RecyclerView recyclerView,final int newState){ super.onScrollStateChanged(recyclerView,newState); if (newState == RecyclerView.SCROLL_STATE_IDLE) {
It works as expected until the current position is different from the target, and there is something to actually scroll through. It is also very possible that the list is already in the correct position, and the call to scrollToPosition() has no effect, onScrollStateChanged() does not start, as well as our animation logic. As a workaround, I can think of this:
final int firstVisibleItemPosition = layoutManager.findFirstCompletelyVisibleItemPosition(); if (firstVisibleItemPosition == targetPosition){ blink(); } else { [previous code block] }
but is this really the best solution? It seems natural to me that each consecutive call to scrollToPosition() a consistent response onScrollStop() , regardless of the movement of the visual list, because none of my cases predicted what would happen on the screen (whether it would move or not?) And try to crack this is. All I know as the API user is that scrollToPosition() been called, and I expect the corresponding callback to be triggered.
An interesting fact: if you extend the RecyclerView.SmoothScroller method and override onStop() , then you are notified all the time. The problem with this approach is that it got a little activated before scrolling the list stops ¯ \ _ (ツ) _ / ¯.
source share