Android RecyclerView overlap items (Card stacks)

亡梦爱人 提交于 2019-12-01 07:55:26

问题


How can I overlap items in RecyclerView? Like stacking cards.

Thanks in advance.


回答1:


You have to write your own LayoutManager or extends LinearLayoutManager




回答2:


To overlap recyclerView rows, you can use this.

Add this class to your activity. You can customize the vertOverlap.

   public class OverlapDecoration extends RecyclerView.ItemDecoration {

    private final static int vertOverlap = -40;

    @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, vertOverlap, 0, 0);


    }
} `

After that add your decoration to recyclerView before setting its layout manager, and we are done.

    mRecyclerView.addItemDecoration(new OverlapDecoration());
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

Thanks to the @MojoTosh https://stackoverflow.com/a/29067942/6255073



来源:https://stackoverflow.com/questions/32319541/android-recyclerview-overlap-items-card-stacks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!