Android 设置 recyclerview的item之间间距的简单方式

1.

public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private int space;

    public SpacesItemDecoration(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.top = space;
        outRect.bottom = space;
        outRect.left = space;
        outRect.right = space;
    }
}

2.

SpacesItemDecoration decoration = new SpacesItemDecoration(8);//这个数字8就是你想设置的间距距离

3.

recyclerview.addItemDecoration(decoration);

 

你可能感兴趣的:(Android 设置 recyclerview的item之间间距的简单方式)