Skip to content

Commit

Permalink
NormalDecoration
Browse files Browse the repository at this point in the history
  • Loading branch information
SiberiaDante committed Nov 30, 2017
1 parent 0f8f04d commit efa9ae9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions SDAndroidLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.midSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 7
versionName "1.0.7"
versionCode 8
versionName "1.0.8"
consumerProguardFiles 'siberiadante-proguard-rules.pro'
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.siberiadante.lib.view;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
* @Created SiberiaDante
* @Describe:
* @CreateTime: 2017/11/30
* @UpDateTime:
* @Email: 2654828081@qq.com
* @GitHub: https://github.com/SiberiaDante
*/

public class NormalDecoration extends RecyclerView.ItemDecoration {

private Paint mPaint;
private int mHeight;

public NormalDecoration(int color, int height) {
this.mHeight = height;
mPaint = new Paint();
mPaint.setColor(color);
mPaint.setAntiAlias(true);
}

@Override

public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
int childCount = parent.getChildCount();
Rect rect = new Rect();
rect.left = parent.getPaddingLeft();
rect.right = parent.getWidth() - parent.getPaddingRight();
for (int i = 0; i < childCount; i++) {
View childView = parent.getChildAt(i);
rect.top = childView.getBottom();
rect.bottom = rect.top + mHeight;
c.drawRect(rect, mPaint);
}
}


@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
outRect.bottom += mHeight;
}
}

0 comments on commit efa9ae9

Please sign in to comment.