2

下の図のような仕切りを取得したい:

私が欲しいもの

すべての列を同じ幅で、間隔を変えたい。現在、最初の列と最後の列は次のように切り取られています。

私が今持っているもの

これが私のもの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));
    }
}

どうすればこれを修正できますか? ありがとう!

4

1 に答える 1