Making animation frame from images in Android (Part 2)

In part 1, I have presented the way to make frame-by-frame animation from images in drawables folder.
Okey, there is a simple way to create "Gif Image" in android based on AnimationDrawable object in Android API and now, I show a simple example for this.



1. Start Eclipse and start a new android project.
2. Put all images to make animation in drawables folder:

3. Create animations in anim folder
In my project, I would like to make 2 animations (loading and firework) so we have 2 xml files like this:
As you can see, An AnimationDrawable defined in XML consists of a single <animation-list> element, and a series of nested <item> tags. Each item defines a frame of the animation.

4. Coding for activity to use it:
We define activity layout simple like this:
In ActivityAnimation.java, after get view from xml, call start() method to run animation.
Full code:
5. Build and Run
Like code descriptions, LoadingAnimation run in 5 seconds and Firework Animation run after that.
Screens result (click for full size):
pic name pic name pic name

Share


Previous post
« Prev Post
Next post
Next Post »