我想得到如下图所示的分隔符:
我希望所有列的宽度相同但间距不同。现在我的第一列和最后一列被剪成这样:
这是我的ItemDecoration
:
public class MoreIndexItemDividerDecoration extends RecyclerView.ItemDecoration {
private GridLayoutManager mGridLayoutManager;
private GridLayoutManager.SpanSizeLookup mSpanSizeLookup;
private int mSpanCount;
public MoreIndexItemDividerDecoration(GridLayoutManager manager, int spanCount) {
mGridLayoutManager = manager;
mSpanSizeLookup = mGridLayoutManager.getSpanSizeLookup();
mSpanCount = spanCount;
}
@Override
public void getItemOffsets(Rect outRect, View child, RecyclerView parent, RecyclerView.State state) {
int pos = parent.getChildLayoutPosition(child);
int left = 0;
int top = 0;
int right = 0;
int bottom = 0;
if (mGridLayoutManager.getItemViewType(child) == 1) {
if (mSpanSizeLookup.getSpanIndex(pos, mSpanCount) == 0) {
left = 50;
} else {
left = 5;
}
if (mSpanSizeLookup.getSpanIndex(pos, mSpanCount) == mSpanCount - 1) {
right = 50;
} else {
right = 5;
}
top = 5;
bottom = 5;
} else {
if (mSpanSizeLookup.getSpanGroupIndex(pos, 4) != 0) {
top = 45;
}
bottom = 45;
}
outRect.set(left, top, right, bottom);
HtscLog.e("child pos: " + pos + " span size: " + mSpanSizeLookup.getSpanSize(pos) + " group index: " + mSpanSizeLookup.getSpanGroupIndex(pos, 4) + " index: " + mSpanSizeLookup.getSpanIndex(pos, 4) + " view type: " + mGridLayoutManager.getItemViewType(child));
}
}
我怎样才能解决这个问题?谢谢!