Anoop
Anoop

Reputation: 3

Recyclerview items as a stack

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));

Upvotes: 0

Views: 1863

Answers (1)

Rajan Kali
Rajan Kali

Reputation: 12953

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));

Upvotes: 1

Related Questions