先画俩矩形

f425642ce32a363304a3480e44ad0eaf.png 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);

8ef1be41cd6129b9ce7031d5fe1215fc.png

然后 说是 有讲究 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);

47c5cb6d6c65e6682afcc9048125631a.png 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);

b12605c5f524c5e980b458f693208b7e.png

c77508d2fa47a1cf33b12d1f408747f5.png

第二个 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);

1fb61e38b7a0ad39c07759d5bd2561fc.png 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);

f849a9d7c2c580d40f1aee2ba684e4ca.png 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);

625fdaf083db247cd9a2dc945668ad28.png

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐