代码动态设置圆角,使用Canvas绘制
private Paint mPaint;
private float mRadius;
private void init(){
LogHelper.debugLog(mTAG, "init w="+getWidth()+"/h="+getHeight());
mRadius = Util.convertIn(6);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
}
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
LogHelper.debugLog(mTAG, "draw w="+getWidth()+"/h="+getHeight());
Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
Canvas canvas2 = new Canvas(bitmap);
super.draw(canvas2);
Path path = new Path();
path.addRect(new RectF(0, 0, getWidth(), getHeight()), Direction.CW);
path.addRoundRect(new RectF(0, 0, getWidth(), getHeight()), mRadius, mRadius, Direction.CCW);
canvas2.drawPath(path, mPaint);
canvas.drawBitmap(bitmap, 0, 0, null);
bitmap.recycle();
}