Delete one shape from another using android.graphics.Path

what I'm trying to draw is the following: Screen shot But with a plus instead of a minus sign in the center of the arrow.

I want to subtract the minus from the shape of the white base. It is strange that works fine for the minus, but if I draw a plus sign, instead, it no longer subtracts it, but adds it to the main path.

My minus subtraction code is as follows

Path base = new Path(); [... draw the arrow ] Path subtract = new Path(); subtract.moveTo(-xBarWidth/2, -xBarHeight/2); // center the path subtract.rLineTo(xBarWidth, 0); subtract.rLineTo(0, xBarHeight); subtract.rLineTo(-xBarWidth, 0); subtract.rLineTo(0, -xBarHeight); base.add(subtract); [in paint() function: canvas.draw(base, paint)] 

Code for the plus sign:

 int halfBarWidth = xBarWidth/2; subtract.moveTo(-halfBarWidth, -xBarHeight/2); subtract.rLineTo(halfBarWidth, 0); subtract.rLineTo(0, halfBarWidth); subtract.rLineTo(xBarHeight, 0); subtract.rLineTo(0, -halfBarWidth); subtract.rLineTo(halfBarWidth, 0); subtract.rLineTo(0, -xBarHeight); subtract.rLineTo(-halfBarWidth, 0); subtract.rLineTo(0, -halfBarWidth); subtract.rLineTo(-xBarHeight, 0); subtract.rLineTo(0, halfBarWidth); subtract.rLineTo(-halfBarWidth, 0); subtract.rLineTo(0, xBarHeight); 

However, now he draws a white plus on top of the arrow. I tried subtract.setFillType(FillType.INVERSE_EVEN_ODD) , but nothing changed.

Unfortunately, I can not find any help in the api.

+4
source share
1 answer

maybe this will help someone: I had to set the base fillType to EVEN_ODD

 base.setFillType(FillType.EVEN_ODD); 
+5
source

Source: https://habr.com/ru/post/1388855/


All Articles