RecyclerView的行间距&&RecyclerView的Item间距&&

新建立一个工具类起名SpaceItemDecoration


public class SpacesItemDecoration extends RecyclerView.ItemDecoration {//设置每个Item的间距
    private int space;

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

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.left = space;
        outRect.right = space;
        outRect.bottom = space;
        if (parent.getChildAdapterPosition(view) == 0) {
            outRect.top = space;
        }
    }
}
当你要使用的时候就要new一个这个出来


使用方法如下

SpacesItemDecoration decoration = new SpacesItemDecoration(16);
recyclerViewDelicious.addItemDecoration(decoration);


你可能感兴趣的:(Android)