How should I call the onDraw() method of an Android view 30 times per second
-
24-09-2019 - |
Question
For Android, I have a custom view which I fill up with primitive shapes in the onDraw() method.
Coming from a Processing background, I expected the draw method to be called automatically 30 times per second, but its clear that that's not how android views work.
So how should I go about calling this method 30 times per second?
Solution
Use an Animation, and call startAnimation() on it from your View.
I don't know that you can set a target framerate -- rather, you're expected to set start and end points in time, and be able to interpolate for any point in time between the two.
If you don't like this approach, you might consider having another thread which periodically calls view.postInvalidate()
to request that your View
be redrawn.