是否可以将Android Recyclerview项目创建为堆栈。顶部项下需要多个项,还需要在前一项的底部看到堆叠项。

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

最佳答案

使用以下命令从底部堆叠物品

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


并在装饰器中提供bottom边距,而不是top边距

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

09-26 08:52