Faisal Alqadi
Faisal Alqadi

Reputation: 11

Android: Animate a line being drawn using canvas

I have this custom View. In this custom view, I am drawing a line graph. I use a canvas and paint objects to draw the points of the line, as well as connect the points themselves using the drawLine() function of the canvas. This works fine, except I'm looking to animate the line being drawn.

I reckon I could break the drawLine call into multiple calls depending on the length of the line with a small delay between each call, but I feel like that would be resource-intensive and may affect performance when dealing with a large amount of points/lines. What do you guys think? Is there another way?

Any tips/hints are welcome, thanks.

Upvotes: 1

Views: 725

Answers (1)

beSpark
beSpark

Reputation: 135

Actual drawings will be performed on canvas.invalidate(). If you set time between your invalidate calls, for example, to 1/24 sec, you may have as many calls to draw your lines - you will have updates on the screen 24 times a second, like in a movie. Actual calls to draw lines will, as I think,not be a problem if you have hundreds or thousands lines.

Upvotes: 1

Related Questions