Strange behavior when drawing a ring using Path.arcTo () in Android

I implemented an animated drawing ring, starting to use it widely at an angle from 0 to 360. However, when the tail of the ring meets its head at an angle of 360 degrees, the whole picture disappears.

This is my code for the ring in onDraw()

  float startAngle = 270; float sweepAngle = -359; paint.setColor(Color.DKGRAY); paint.setShadowLayer(4, 2, 2, 0x80000000); rectF.set(cenX - outerRadius, cenY - outerRadius, cenX + outerRadius, cenY + outerRadius); path.arcTo(rectF, startAngle, sweepAngle); //canvas.drawArc(rectF, 0, 360, false, paint); rectF.set(cenX - innerRadius, cenY - innerRadius, cenX + innerRadius, cenY + innerRadius); /*paint.reset(); paint.setAntiAlias(true); paint.setColor(Color.WHITE); canvas.drawArc(rectF, 0, 360, false, paint);*/ path.arcTo(rectF, startAngle + sweepAngle, -(sweepAngle)); canvas.drawPath(path, paint); 

and this is the result

enter image description here

Note that I set sweepAngle to -359 before it becomes a circle. However, if I change sweepAngle to -360. He produces this result.

enter image description here

He is disappearing !! Does anyone know how to solve this, please help me?

Thanks.

PS. I do not want to use drawArc() because I want to make a hole inside the ring. With drawArc() my button will disappear.

+7
android android-custom-view drawing
source share
2 answers

I assume the android will be mod 360 before drawing it. So x - 360 === x and draw nothing!

+2
source share

I was late with this, but solved it by adding a solid circle as the last frame of the animation (I used AnimationDrawable, but the idea is the same in this case). All drawing code was the same for the last frame, except for one line:

replace:

 mPath.arcTo(rectF, startAngle, sweepAngle); 

with something like:

 mPath.addCircle(cenX, cenY, innerRadius, Path.Direction.CCW); 
+1
source share

All Articles