Dav Dav - 4 months ago 15
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)
{
super.onDraw(canvas);

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

Answer

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(outerPath);
canvas.clipPath(innerPath, Region.Op.DIFFERENCE);

Along with that disable Hardware Acceleration on the view:

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Comments