-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f8f04d
commit efa9ae9
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
SDAndroidLib/src/main/java/com/siberiadante/lib/view/NormalDecoration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |