Androidの最も簡単な円形のピクチャー、枠付き
1018 ワード
public class XCRoundRectImageView extends ImageView{
public XCRoundRectImageView(Context context) {
this(context,null);
}
public XCRoundRectImageView(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
public XCRoundRectImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
/**
*
* @author caizhiming
*/
@Override
protected void onDraw(Canvas canvas) {
Path mPath = new Path();
int width = getMeasuredWidth();
int height = getMeasuredHeight();
mPath.addCircle(width/2, height/2, height/2, Path.Direction.CW);
canvas.clipPath(mPath);//
super.onDraw(canvas);
//
Paint paint=new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(10);
paint.setColor(Color.RED);
canvas.drawPath(mPath,paint);
}
}