Dav Dav - 7 months ago 33
Android Question

How to fill area between two circle in canvas?

I want to fill area between two circle in canvas
enter image description here

this is my ondraw

protected void onDraw(Canvas canvas)

canvas.drawCircle(centerX, centerY, radarRadius / 3, mPaintCircle);
canvas.drawCircle(centerX, centerY, 3 * radarRadius / 7, mPaintCircle);


You can create two circular paths and clip the canvas like this:

Path outerPath = new Path();
outerPath.addCircle(centerX, centerY, outerRadius, Direction.CW);
Path innerPath = new Path();
innerPath.addCircle(centerX, centerY, innerRadius, Direction.CW);
canvas.clipPath(innerPath, Region.Op.DIFFERENCE);

Along with that disable Hardware Acceleration on the view:

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);