Android: CustomView Circle Stroke not smooth

810 Views Asked by At

I have following code in my onDraw method:

canvas.drawArc(rect, -90, 360, true, bgpaint);
if(isFocussed)
            canvas.drawArc(rect, -90, 360, true, strokePaint);

for strokePaint, this is what I have in my init() method:

strokePaint = new Paint();
strokePaint.setColor(Color.YELLOW);
strokePaint.setAntiAlias(true);        
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setStrokeWidth(2);

Whenever the strokePaint comes into play, the circular stroke is not smooth. The stroke is flat by little bit at top, bottom, left and right.

How do I fix this problem?

Screenshot of the problematic circle:

enter image description here

2

There are 2 best solutions below

3
On BEST ANSWER

You have to take the stroke width in account when drawing. Just make your shape smaller about half of it.

Though I can't say it for sure depending on your code, I just think that you are drawing outside of bounds of your view. That's a common issue.

4
On

Try with this setAntiAlias(true)and setStrokeCap(Paint.Cap.ROUND)