Recyclerview - 从下到上重叠项目 [英] Recyclerview - Overlap items bottom to top

查看:37
本文介绍了Recyclerview - 从下到上重叠项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为这样的项目设置了负边距:-

I have set the negative margin for items like this:-

ItemDecoration.java

public class ItemDecorator extends RecyclerView.ItemDecoration {
    private final int mSpace;

    public ItemDecorator(int space) {
        this.mSpace = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int position = parent.getChildAdapterPosition(view);
        if (position != 0)
            outRect.top = mSpace;
    }
}

MainActivity.java

recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new ItemDecorator(-80));

这会导致顶部项目与顶部项目重叠后堆叠最低和下一个项目.我希望顶部项目与其下一个项目重叠,依此类推.

This causes top item to stack lowest and next item after the top item overlaps it. I want top item to overlap its next item and so on.

当前视图

必需的视图

推荐答案

试试这种方式,并以相反的方向渲染你的回收器视图.

Try this way and render your recycler view in reverse direction.

LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setReverseLayout(true);
        layoutManager.setStackFromEnd(true);
        recyclerView.setLayoutManager(layoutManager);

这是工作示例 GitHub 链接

这篇关于Recyclerview - 从下到上重叠项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆