Best practices for animating shapes under Android Canvas

Viewed 906

I have a custom view that draws a few circles and about 10 arches that are constantly updating (rotation and size change). I am trying to animate this whole process, but I couldn't find any good practices for doing so under Canvas (I know the basics - use dp instead of px and so on), but I don't know hot to properly do the animation part.

Right now I'm iterating trough all of my objects, perform some calculations to determine the future position and draw them, but it looks choppy. Here is what I'm currently doing:

@Override
protected void onDraw(Canvas canvas) {
    for(Arch arch : arches) {
        arch.update();
        canvas.drawArc(arch.getRect(), -arch.getCurrentRotation(), arch.getSweepAngle(), true, paint);
    }

    //logo.draw(canvas);

    canvas.drawCircle(width / 2, height / 2, circle_size, paint_opaque);

    logo.draw(canvas);

    int textX = (int) (width / 2);
    int textY = (int) ((height / 2) - ((paint_text.descent() + paint_text.ascent()) / 2));

    canvas.drawText(text, textX, textY, paint_text);
    invalidate();
}
1 Answers
Related