代码动态设置远角

来源:互联网 发布:mac双系统快速切换 编辑:程序博客网 时间:2024/05/14 09:16

代码动态设置圆角,使用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));}



@Overridepublic void draw(Canvas canvas) {// TODO Auto-generated method stubLogHelper.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();}


1 0
原创粉丝点击