Custom scale animation
I have an 800x480 image, and I want to have a scale animation so that the image scales to 960x576. I开发者_开发技巧 know that Android has a ScaleAnimation
class for this, but I also want the user to be able to pause the animation while it's scaling and resume from where they paused.
How can I do this?
I did write some custom refresh loop but it's not super smooth like the ScaleAnimation
class. The custom refresh loop just calculates the change in width and height that is desired per 25 ms and then sets the new width to the Rect
. Then the loop calls invalidate.
//Reset the image size
x = (x + dx);
y = (y + dy);
imageWidth = (imageWidth + dWidth);
imageHeight = (imageHeight + dHeight);
I then draw on the canvas.
outputRect.set((int)(-x), (int)(-y), (int)imageWidth, (int)imageHeight);
canvas.drawBitmap(bitmap, srcRect, outputRect, paint);
How can I do this just as smoothly as with the Android OS or more efficiently?
I would suggest using Androids ScaleAnimation. You can anim.cancel() an animation and it might resume right where it was canceled if started again. The documentation suggest calling reset() before reusing an animation, so that might work.
If it does not work, you can save the animation-state on pause and create a new animation from that point on, if the user resumes the animation.
精彩评论