android 圆角控件

参考:

https://github.com/angcyo/RoundAngleFrameLayout

核心代码:

 @Override
    protected void dispatchDraw(Canvas canvas) {
canvas.saveLayer(new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), imagePaint,Canvas.ALL_SAVE_FLAG);
        super.dispatchDraw(canvas);
        drawTopLeft(canvas);//用PorterDuffXfermode
        drawTopRight(canvas);//用PorterDuffXfermode
        drawBottomLeft(canvas);//用PorterDuffXfermode
        drawBottomRight(canvas);//用PorterDuffXfermode
        canvas.restore();
    }

  

   roundPaint = new Paint();
        roundPaint.setColor(Color.WHITE);
        roundPaint.setAntiAlias(true);
        roundPaint.setStyle(Paint.Style.FILL);
        roundPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));

        imagePaint = new Paint();
        imagePaint.setXfermode(null);

 

posted on 2017-07-18 18:22  wjw334  阅读(167)  评论(0编辑  收藏  举报

导航