Android 自定义View Clip

先画俩矩形

Android 自定义View Clip


        RectF rectF = new RectF(0,0,300,300);
        canvas.drawRect(rectF,mPaint);

        mPaint.setColor(Color.GREEN);

        RectF rectF2 = new RectF(400,400,600,600);
        canvas.drawRect(rectF2,mPaint);

把他俩重在一起  看看

Android 自定义View Clip

然后 说是 有讲究


        canvas.clipRect(0, 0, 300, 300);
//        canvas.clipRect(200, 200, 500, 500, Region.Op.DIFFERENCE);


        RectF rectF = new RectF(0,0,300,300);
        canvas.drawRect(rectF,mPaint);

        mPaint.setColor(Color.GREEN);

        RectF rectF2 = new RectF(200,200,500,500);
        canvas.drawRect(rectF2,mPaint);

Android 自定义View Clip

    canvas.clipRect(0, 0, 300, 300);
        canvas.clipRect(200, 200, 500, 500, Region.Op.DIFFERENCE);


        RectF rectF = new RectF(0,0,300,300);
        canvas.drawRect(rectF,mPaint);

        mPaint.setColor(Color.GREEN);

        RectF rectF2 = new RectF(200,200,500,500);
        canvas.drawRect(rectF2,mPaint);

Android 自定义View Clip

 

Android 自定义View Clip

第二个

  canvas.clipRect(0, 0, 300, 300);
        canvas.clipRect(200, 200, 500, 500, Region.Op.INTERSECT);


        RectF rectF = new RectF(0,0,300,300);
        canvas.drawRect(rectF,mPaint);

        mPaint.setColor(Color.GREEN);

        RectF rectF2 = new RectF(200,200,500,500);
        canvas.drawRect(rectF2,mPaint);

Android 自定义View Clip

    canvas.clipRect(0, 0, 300, 300, Region.Op.DIFFERENCE);
        canvas.clipRect(200, 200, 500, 500);

        RectF rectF = new RectF(0, 0, 300, 300);
        canvas.drawRect(rectF, mPaint);

        mPaint.setColor(Color.GREEN);

        RectF rectF2 = new RectF(200, 200, 500, 500);
        canvas.drawRect(rectF2, mPaint);

 

Android 自定义View Clip



    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

        canvas.clipPath(path);

    } else {

        canvas.clipPath(path, Region.Op.XOR);// REPLACE、UNION 等类型

    }

     canvas.clipRect(200, 200, 500, 500, Region.Op.INTERSECT);


        RectF rectF = new RectF(0, 0, 300, 300);
        canvas.drawRect(rectF, mPaint);

        canvas.clipRect(0, 0, 300, 300, Region.Op.DIFFERENCE);

        mPaint.setColor(Color.GREEN);

        RectF rectF2 = new RectF(200, 200, 500, 500);
        canvas.drawRect(rectF2, mPaint);

Android 自定义View Clip

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

上一篇:文字两种颜色渐变


下一篇:安卓自定义View进阶-Canvas之画布操作 转载