Android 自定义View Clip

先画俩矩形

Android 自定义View Clip_第1张图片


        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_第2张图片

然后 说是 有讲究


        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_第3张图片

    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_第4张图片

 

Android 自定义View Clip_第5张图片

第二个

  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_第6张图片

    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_第7张图片



    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_第8张图片

 

得知  XOR,UNION 等 都煤球了 ,无意发现XFermode 可以实现这个效果

https://blog.csdn.net/FlyPig_Vip/article/details/100981315

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Android 自定义View Clip)