Skip to content

Instantly share code, notes, and snippets.

@guavabot
Last active September 30, 2016 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guavabot/c9032ac6082682b5079a528c11abe185 to your computer and use it in GitHub Desktop.
Save guavabot/c9032ac6082682b5079a528c11abe185 to your computer and use it in GitHub Desktop.
Fix absolute RecyclerView scroll when items change size and scroll callback is not received
recyclerView.addOnScrollListener(new RecyclerScrollListener());
private static class RecyclerScrollListener extends RecyclerView.OnScrollListener {
private int overallYScroll;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
overallYScroll += dy;
//If first item is visible, override absolute scroll with its position in the RecyclerView.
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(0);
if (viewHolder != null) {
overallYScroll = -viewHolder.itemView.getTop();
//Add RecyclerView padding if necessary (use clipToPadding=false if you set a padding on it.)
//overallYScroll += getResources().getDimensionPixelOffset(R.dimen.padding_top_recyclerview);
}
//use overallYScroll
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment