View ChangeHeightSnippet.java
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) {
View AddOnScrollListener.java
addOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (getLayoutManager() instanceof LinearLayoutManager) {
LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) {