package com.yeshi.ec.rebate.myapplication.util;
|
|
import android.content.Context;
|
import android.graphics.Canvas;
|
import android.graphics.Path;
|
import android.graphics.RectF;
|
import android.util.AttributeSet;
|
|
import com.app.hubert.guide.util.ScreenUtils;
|
|
/**
|
* 左上右上圆角图片
|
*/
|
public class RoundedImage2View extends android.support.v7.widget.AppCompatImageView {
|
|
/*圆角的半径,依次为左上角xy半径,右上角,右下角,左下角*/
|
// private static float[] rids = new float[8];//= {10.0f, 10.0f, 10.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f,};
|
private static float r = 0.0f;
|
private float[] rids;
|
|
|
public RoundedImage2View(Context context) {
|
this(context, null);
|
}
|
|
public RoundedImage2View(Context context, AttributeSet attrs) {
|
this(context, attrs, 0);
|
}
|
|
public RoundedImage2View(Context context, AttributeSet attrs, int defStyleAttr) {
|
super(context, attrs, defStyleAttr);
|
r = ScreenUtils.dp2px(context, 10);
|
rids = new float[]{r, r, r, r, r, r, r, r,};//四个角都圆角
|
}
|
|
|
/**
|
* 画图
|
*
|
* @param canvas
|
*/
|
protected void onDraw(Canvas canvas) {
|
Path path = new Path();
|
int w = this.getWidth();
|
int h = this.getHeight();
|
/*向路径中添加圆角矩形。radii数组定义圆角矩形的四个圆角的x,y半径。radii长度必须为8*/
|
path.addRoundRect(new RectF(0, 0, w, h), rids, Path.Direction.CW);
|
canvas.clipPath(path);
|
super.onDraw(canvas);
|
}
|
}
|