目前正尝试使用此类:
public class EqualItemSpacingDecoration extends RecyclerView.ItemDecoration {
private int space;
public EqualItemSpacingDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
outRect.bottom = space;
if (parent.getChildLayoutPosition(view) < 2)
outRect.top = space;
if (parent.getChildLayoutPosition(view) % 2 == 0) {
outRect.left = space;
outRect.right = space / 2;
} else {
outRect.left = space / 2;
outRect.right = space;
}
}
}
并使用此代码:
recycler.addItemDecoration(new EqualItemSpacingDecoration(12));
我如何解决此问题?