package com.basic.security.widget;
|
|
import android.content.Context;
|
import android.graphics.Canvas;
|
import android.graphics.Paint;
|
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuffXfermode;
|
import android.graphics.RectF;
|
import android.util.AttributeSet;
|
import android.view.View;
|
import android.widget.ImageView;
|
|
public class BorderView extends ImageView {
|
private RectF circleRect;
|
private int radius;
|
|
public BorderView(Context context) {
|
super(context);
|
initView();
|
}
|
|
public BorderView(Context context, AttributeSet attrs) {
|
super(context, attrs);
|
initView();
|
}
|
|
public BorderView(Context context, AttributeSet attrs, int defStyleAttr) {
|
super(context, attrs, defStyleAttr);
|
initView();
|
}
|
|
@Override
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
// if (attribute != null) {
|
// int layoutWidth = attribute.getLayout_width();
|
// int layoutHeight = attribute.getLayout_height();
|
// if (layoutWidth != 0 || layoutHeight != 0) {
|
// setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
|
// }
|
// }
|
}
|
|
public void setMeasuredDimension1(int measuredWidth, int measuredHeight) {
|
setMeasuredDimension(measuredWidth, measuredHeight);
|
}
|
|
@Override
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
super.onLayout(changed, left, top, right, bottom);
|
}
|
|
private void initView() {
|
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
}
|
|
public void onDraw(Canvas canvas) {
|
super.onDraw(canvas);
|
radius = (int) getResources().getDimension(com.basic.security.utils.RUtils.R_dimen_corner_radius);
|
circleRect = new RectF(0, 0, this.getWidth(), this.getHeight());
|
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
paint.setColor(getResources().getColor(com.basic.security.utils.RUtils.R_color_bg_color));
|
paint.setStyle(Paint.Style.FILL);
|
canvas.drawPaint(paint);
|
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
|
canvas.drawRoundRect(circleRect, radius, radius, paint);
|
}
|
}
|