Last active
September 30, 2016 09:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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