我有一个带有GridLayoutManager的RecyclerView。
我设置了自定义ItemDecoration:
public class ListDetailsItemDecoration extends RecyclerView.ItemDecoration {
private int space;
public ListDetailsItemDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int itemPosition = parent.getChildPosition(view);
outRect.left = space;
outRect.right = space;
outRect.bottom = space;
if(itemPosition == 0 || itemPosition == 1) {
outRect.top = space;
}
if(itemPosition % 2 == 0) {
outRect.right = space / 2;
} else {
outRect.left = space / 2;
}
}
}
在我需要移除任何人之前,它很有用。
notifyItemRemoved(position);
网格未调整大小。
有什么想法吗?