How can I draw line/arc with rounded corners as you can see on the picture below?
I need to draw this on Canvas.

I think you can workaround this by drawing three lines with a partial overlap:
Paint.Cap.ROUNDPaint.Cap.BUTTAssuming your input data is
float lineWidth = 20;
float lineRadius = 100;
float cornerRadius = 2;
You go as follows,
float width, radius;
// Draw outer lines
paint.setStrokeCap(Paint.Cap.ROUND);
width = cornerRadius * 2;
// Draw inner
radius = lineRadius - lineWidth/2f + cornerRadius;
canvas.draw(...)
// Draw outer
radius = lineRadius + lineWidth/2f - cornerRadius;
canvas.draw(...)
// Draw center
paint.setStrokeCap(Paint.Cap.BUTT);
width = lineWidth - 2f*cornerRadius;
radius = lineRadius;
canvas.draw(...)
You might need to slightly alter the arc angle for the center line (it must be cornerRadius longer, on each side) but that is easy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With