Skip to content

Instantly share code, notes, and snippets.

View developer-shivam's full-sized avatar
🎯
Focusing

Shivam Satija developer-shivam

🎯
Focusing
View GitHub Profile
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) {
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) {