I have the following custom view:
This I have achieved by using the Canvas' drawArc()
method. However, with this drawArc()
method I cannot limit the arc's inner radius.
What I'd like to have is something like this:
where there is only an outer ring left.
What I need is an drawArc()
function where I can set the inner radius of the arc. Anyone an idea how to do that?
(BTW, overpainting the inner area doesn't work, because it needs to be transparent. Painting an inner circle with Color.TRANSPARENT
after painting the red and blue cones doesn't remove the old color. It just puts another layer on top, which is transparent and through which I can still see the red and blue)
You can do this:
Paint paint = new Paint();
final RectF rect = new RectF();
//Example values
rect.set(mWidth/2- mRadius, mHeight/2 - mRadius, mWidth/2 + mRadius, mHeight/2 + mRadius);
paint.setColor(Color.GREEN);
paint.setStrokeWidth(20);
paint.setAntiAlias(true);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStyle(Paint.Style.STROKE);
canvas.drawArc(rect, -90, 360, false, paint);
The key is in paint.setStyle(Paint.Style.STROKE);
, it crops the arc's center with the stroke that you define in setStrokeWidth (in the example draws an arc with a radius of mRadius and 20px thick).
Hope it helps!