Recyclerview-重叠项从下到上 [英] Recyclerview - Overlap items bottom to top
本文介绍了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屋!
查看全文