How to draw animation on a canvas ?(android)

2020-07-18 03:17发布

问题:

I am trying to show an animation on a canvas when user touches to the screen.I know basics and how to draw a bitmap on to canvas but i couldn't find anything good on drawing or showing animation on canvas.i will use frame by frame animation and it will appear at the same position user touched that is why i can't use ImageView.

回答1:

Not sure if there is a built-in way of doing this. But it's fairly straightforward to simply load the bitmaps into an array.

Then call invalidate(), your onDraw() method should invalidate() itself and on the next run calculate which frame to display (by calculating the time the last frame was displayed). Every time you play a frame you increase the frame counter and reset the time counter.

You can use a variable delay, and it's fairly easy to implement.