1
+ package com .siberiadante .lib .view ;
2
+
3
+ import android .graphics .Canvas ;
4
+ import android .graphics .Paint ;
5
+ import android .graphics .Rect ;
6
+ import android .support .v7 .widget .RecyclerView ;
7
+ import android .view .View ;
8
+
9
+ /**
10
+ * @Created SiberiaDante
11
+ * @Describe:
12
+ * @CreateTime: 2017/11/30
13
+ * @UpDateTime:
14
+ * @Email: 2654828081@qq.com
15
+ * @GitHub: https://github.com/SiberiaDante
16
+ */
17
+
18
+ public class NormalDecoration extends RecyclerView .ItemDecoration {
19
+
20
+ private Paint mPaint ;
21
+ private int mHeight ;
22
+
23
+ public NormalDecoration (int color , int height ) {
24
+ this .mHeight = height ;
25
+ mPaint = new Paint ();
26
+ mPaint .setColor (color );
27
+ mPaint .setAntiAlias (true );
28
+ }
29
+
30
+ @ Override
31
+
32
+ public void onDraw (Canvas c , RecyclerView parent , RecyclerView .State state ) {
33
+ super .onDraw (c , parent , state );
34
+ int childCount = parent .getChildCount ();
35
+ Rect rect = new Rect ();
36
+ rect .left = parent .getPaddingLeft ();
37
+ rect .right = parent .getWidth () - parent .getPaddingRight ();
38
+ for (int i = 0 ; i < childCount ; i ++) {
39
+ View childView = parent .getChildAt (i );
40
+ rect .top = childView .getBottom ();
41
+ rect .bottom = rect .top + mHeight ;
42
+ c .drawRect (rect , mPaint );
43
+ }
44
+ }
45
+
46
+
47
+ @ Override
48
+ public void getItemOffsets (Rect outRect , View view , RecyclerView parent , RecyclerView .State state ) {
49
+ super .getItemOffsets (outRect , view , parent , state );
50
+ outRect .bottom += mHeight ;
51
+ }
52
+ }
0 commit comments