Home » Android » set android animation list programmatically

set android animation list programmatically

Posted by: admin June 15, 2020 Leave a comment


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 custom 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.

How to&Answers:

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