我有一个回收站视图,我想在单元格之间添加一个空格。但是,使用下面的代码可以工作,中间的空间增加了一倍。
我怎样才能隔开它们并避免中间的双倍空间?
public class ItemDecorationAlbumColumns extends RecyclerView.ItemDecoration {
private int space;
public ItemDecorationAlbumColumns(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.left = space;
outRect.right = space;
outRect.bottom = space;
// Add top margin only for the first item to avoid double space between items
if(parent.getChildAdapterPosition(view) == 0) {
outRect.top = space;
}
}
}
来电:
recyclerView.addItemDecoration(new ItemDecorationAlbumColumns(50));