Skip to content

Instantly share code, notes, and snippets.

@developer-shivam
Created June 16, 2017 13:52
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 developer-shivam/10b59bb4eb292d2de33ac638577db4e5 to your computer and use it in GitHub Desktop.
Save developer-shivam/10b59bb4eb292d2de33ac638577db4e5 to your computer and use it in GitHub Desktop.
private void changeHeightAccordingToScroll(RecyclerView recyclerView) {
for (int i = 0; i < totalItemsInView; i++) {
View viewToBeResized = recyclerView.getChildAt(i);
if (viewToBeResized != null) {
float distance = getTopOfView(viewToBeResized);
if (distance > maxDistance) {
viewToBeResized.getLayoutParams().height = defaultItemHeight;
viewToBeResized.requestLayout();
} else if (distance <= maxDistance) {
viewToBeResized.getLayoutParams().height = (int) height(distance);
viewToBeResized.requestLayout();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment