-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLinearLayoutSpacesItemDecoration.java
More file actions
54 lines (45 loc) · 1.51 KB
/
LinearLayoutSpacesItemDecoration.java
File metadata and controls
54 lines (45 loc) · 1.51 KB
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.newline.ucos.launcher.utils;
import android.graphics.Rect;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
/**
* @author Realmo
* @version 1.0.0
* @name android-doorway
* @email momo.weiye@gmail.com
* @time 2020/9/8 14:52
* @describe LinearLayout 上下/左右间距的itemdecoration
*/
public class LinearLayoutSpacesItemDecoration extends RecyclerView.ItemDecoration{
int orientation;
//间隔 px
private int space;
//首条头部是否生效间距
private boolean effectFirstTopSpace;
public LinearLayoutSpacesItemDecoration(int orientation, int space) {
this(orientation,space,false);
}
public LinearLayoutSpacesItemDecoration(int orientation, int space,boolean effectFirstTopSpace) {
this.orientation = orientation;
this.space = space;
this.effectFirstTopSpace = effectFirstTopSpace;
}
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
if(orientation == LinearLayoutManager.HORIZONTAL){
if (parent.getChildPosition(view) != 0){
outRect.left = space;
}
}else{
if (parent.getChildPosition(view) != 0){
outRect.top = space;
}else{
if(effectFirstTopSpace){
outRect.top = space;
}
}
}
}
}