是否可以将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));