Spot the bug
This view stutters while animating. Which line is the problem?
class Ring(context: Context) : View(context) {var progress = 0foverride fun onDraw(canvas: Canvas) {val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { strokeWidth = 12f; style = Paint.Style.STROKE }canvas.drawArc(12f, 12f, width - 12f, height - 12f, -90f, progress * 360f, false, paint)}}
Hint 1 of 1
What runs on every frame?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 4
val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { strokeWidth = 12f; style = Paint.Style.STROKE }
A new Paint is allocated on every frame. Create it once as a field and reuse it.