Dav Dav - 1 year ago 114
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);

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download