0

Is it possible to create android Recyclerview items as a stack. More than one items need to come under the top item.Also need to see the stack items on the bottom of the previous item.

public class OverlapDecoration extends RecyclerView.ItemDecoration {

        @Override
        public void getItemOffsets(Rect outRect, View view,
                                   RecyclerView parent,
                                   RecyclerView.State state) {
            final int itemPosition = parent.getChildAdapterPosition(view);
            if (itemPosition == 0) {
                return;
            }
            outRect.set(0, -150, 0, 0);
        }

    }

recyclerView.addItemDecoration(new OverlappDecoration());
recyclerview.setLayoutManager(new LinearLayoutManager(context));
Anas Mehar
  • 2,739
  • 14
  • 25
Anoop
  • 3
  • 4

1 Answers1

1

Stack items from bottom using

LinearLayoutmanager layoutManager = new LinearLayoutManager(this);
layoutManager.setReverseLayout(true);

and provide bottom margin in your decorator instead top margin

public class OverlapDecoration extends RecyclerView.ItemDecoration {

        @Override
        public void getItemOffsets(Rect outRect, View view,
                                   RecyclerView parent,
                                   RecyclerView.State state) {
            final int itemPosition = parent.getChildAdapterPosition(view);
            if (itemPosition == 0) {
                return;
            }
            outRect.set(0, 0, 0, -150);//<-- bottom
        }

    }

recyclerView.addItemDecoration(new OverlappDecoration());
recyclerview.setLayoutManager(new LinearLayoutManager(context));
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37