rk
昨天 4a8ff39b0fab0627ef8f7459587d514cc01c3676
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.doumee.lib_coremodel.view.recyclerview;
 
/**
 * Created by MSI on 2018/5/31.
 */
 
import android.graphics.Rect;
import android.view.View;
 
import androidx.recyclerview.widget.RecyclerView;
 
/**
 * 设置水平方向item间距
 */
public class HorizontalDecoration extends RecyclerView.ItemDecoration {
    private int space;
    private int topSpace;
    private int rightSapce;
 
    //右间距
    public HorizontalDecoration(int space) {
        this.rightSapce = space;
    }
 
    //顶部间距
    public HorizontalDecoration(int space, boolean isTop) {
        if(isTop){
            this.topSpace=space;
        }else {
            this.space = space;
        }
    }
 
    public HorizontalDecoration(int bottom, int top, int right){
        space=bottom;
        topSpace=top;
        rightSapce=right;
    }
 
    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
 
        outRect.bottom=space;
        outRect.top=topSpace;
 
        // Add top margin only for the first item to avoid double space between items
        if (parent.getChildLayoutPosition(view) == 0)
            outRect.left = 0;
        if(rightSapce!=-1){
            outRect.right=rightSapce;
        }
    }
}