I have a callback that is fired after a programmatic scroll to a certain item of a RecyclerView via LinearLayoutManager.smoothScrollToPosition()
. The user taps on an item and the right item is scrolled to the top of the RecyclerView. I subclassed LinearLayoutManager to have it always snap to the top of the item.
This works in case the scroll event is fired, but when the RecyclerView is already in the right position, I don't get the onScrollStateChanged
callback, as no scrolling occurs. Is there a way to get that event anyway? Like decide beforehand whether or not the RecyclerView needs to scroll or not?
I found the following solution myself:
// get the view the user selected
View view = mLayoutManager.findViewByPosition(index);
// get top offset
int offset = view.getTop();
if (offset == 0) { // the view is at the top of the scrollview
showDetailViewInternal(event);
} else {
// scrolling
}