开发者

set android animation list programmatically

I am trying to achieve adding the animated gifs into my application.

1- I am able to download the animated gif from server. 2- I am able to decode the animated gif (using my cu开发者_运维百科stom decoder) and have a separate Bitmap corresponding to its frames.

Now I want to animate it using the frame by frame animation. As i read, to perform the frame by frame animation the first thing that is required is "animation-list".

I want to know how i can create the required "animation-list" programatically containing each Bitmap as a separate frame.


You can use AnimationDrawable similiar to http://androidforums.com/application-development/11620-programmatic-frame-frame-animation-examle-animationdrawable.html but use your own files instead of taken from resources.

Note that you have to be careful about density of screen and bitmaps which are downloaded rather than taken from resources otherwise it might look differently on different screen sizes/resolutions. More about it here: http://developer.android.com/guide/practices/screens_support.html see particularly "Scaling Bitmap Objects created at runtime" chapter


It's important to note that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity, because the AnimationDrawable is not yet fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged() method in your Activity, which will get called when Android brings your window into focus

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜