Commit d6e641b0 authored by 赵鹏翔's avatar 赵鹏翔

update

parent 81c5d3fb
package com.miya.fastcashier.widget;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
/**
* 通用的RecyclerDivider
*/
public class Divider extends RecyclerView.ItemDecoration {
private Paint paint;
private int divideWidth;
public Divider(int divideWidth, int color) {
super();
this.paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(color);
this.divideWidth = divideWidth;
}
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
int left = parent.getPaddingStart();
int right = parent.getMeasuredWidth() - parent.getPaddingEnd();
View child;
int childPosition;
int validChildCount = parent.getChildCount();
for (int i = 0; i < validChildCount; i++) {
child = parent.getChildAt(i);
childPosition = parent.getChildAdapterPosition(child);
if (childPosition == validChildCount - 1) {
break;
}
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
int top = child.getBottom() + layoutParams.bottomMargin;
int bottom = top + divideWidth;
c.drawRect(left, top, right, bottom, paint);
}
}
}
\ No newline at end of file
package com.miya.fastcashier.widget
import android.graphics.Canvas
import android.graphics.Paint
import android.view.View
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
import androidx.recyclerview.widget.RecyclerView
/**
* 通用的RecyclerDivider
*/
class Divider(divideWidth: Int, color: Int) : ItemDecoration() {
private val paint: Paint
private val divideWidth: Int
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val left = parent.paddingStart
val right = parent.measuredWidth - parent.paddingEnd
var child: View
var childPosition: Int
val validChildCount = parent.childCount
for (i in 0 until validChildCount) {
child = parent.getChildAt(i)
childPosition = parent.getChildAdapterPosition(child)
if (childPosition == validChildCount - 1) {
break
}
val layoutParams = child.layoutParams as RecyclerView.LayoutParams
val top = child.bottom + layoutParams.bottomMargin
val bottom = top + divideWidth
c.drawRect(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat(), paint)
}
}
init {
paint = Paint()
paint.isAntiAlias = true
paint.color = color
this.divideWidth = divideWidth
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment