先画俩矩形
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);
把他俩重在一起 看看
然后 说是 有讲究
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);
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);
第二个
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);
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);
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);