private int mRadius;
/**
- 3x3 矩阵,主要用于缩小放大
*/
private Matrix mMatrix;
/**
- 渲染图像,使用图像为绘制图形着色
*/
private BitmapShader mBitmapShader;
/**
- view的宽度
*/
private int mWidth;
private RectF mRoundRect;
/**
- 构造函数:获取自定义属性
*/
public RoundImageView(Context context, AttributeSet attrs) {
super(context, attrs);
mMatrix = new Matrix();
mBitmapPaint = new Paint();
mBitmapPaint.setAntiAlias(true);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.RoundImageView);
mBorderRadius = a.getDimensionPixelSize(
R.styleable.RoundImageView_borderRadius, (int) TypedValue
.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
BODER_RADIUS_DEFAULT, getResources()
.getDisplayMetrics()));// 默认为10dp
type = a.getInt(R.styleable.RoundImageView_type, TYPE_CIRCLE);// 默认为Circle
a.recycle();
}
/**
- 关于view的宽高:主要用于当设置类型为圆形时,我们强制让view的宽和高一致
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Log.e(“TAG”, “onMeasure”);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
/**
- 如果类型是圆形,则强制改变view的宽高一致,以小值为准;如果是圆角则不用管宽高问题
*/
if (type == TYPE_CIRCLE) {
mWidth = Math.min(getMeasuredWidth(), getMeasuredHeight());
mRadius = mWidth / 2;
setMeasuredDimension(mWidth, mWidth);
}
}
/**
-
- 设置BitmapShader
-
- 绘制
*/
@Override