How to draw animation on a canvas ?(android)

2020-07-18 02:25发布

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条回答
淡お忘
2楼-- · 2020-07-18 03:09

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.

查看更多
登录 后发表回答