Skip to content

Commit efa9ae9

Browse files
committed
NormalDecoration
1 parent 0f8f04d commit efa9ae9

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

SDAndroidLib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
defaultConfig {
1010
minSdkVersion rootProject.ext.midSdkVersion
1111
targetSdkVersion rootProject.ext.targetSdkVersion
12-
versionCode 7
13-
versionName "1.0.7"
12+
versionCode 8
13+
versionName "1.0.8"
1414
consumerProguardFiles 'siberiadante-proguard-rules.pro'
1515
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1616
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)