Customize Android Animation List

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

1- I can upload an animated gif from the server. 2- I can decode an animated gif (using my own custom decoder) and have a separate bitmap corresponding to its frames.

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

I want to know how I can create the required "animation list" programmatically containing each bitmap as a separate frame.

+7
source share
2 answers

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

Please note that you must be careful with the density of the screen and bitmaps that are downloaded, not retrieved from resources, otherwise it may look different at different screen sizes / resolutions. More about this here: http://developer.android.com/guide/practices/screens_support.html see, In particular, the section "Scaling raster objects created at runtime"

+9
source

It is important to note that the start () method called in AnimationDrawable cannot be called during the onCreate () method of your Activity, because AnimationDrawable is not yet fully bound to the window. If you want to immediately play the animation without requiring interaction, you can call it from the onWindowFocusChanged () method in your Activity, which is called when Android switches your window to focus.

0
source

All Articles