Frame animation in android

Frame animation is explained below using a example that uses different loading images to creating a animation which continues for the specified time.
An animation defined which shows a sequence of images in order (like a film). class is used for animations

The AnimationDrawable class is the basis for loading drawable resources one after another to create an animation. Notice that the animation is started in class starter’s in public void run() .


import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
public class SplashScreenActivity extends Activity
AnimationDrawable animation;
protected boolean _active = true;
protected int _splashTime = 5000;
public void onCreate(Bundle savedInstanceState)

animation = new AnimationDrawable();

// the following code adds frames AnimationDrawable type animation and each frame //fetches the image from drawable ,which is fetched from resource folder. animation.addFrame(getResources().getDrawable(R.drawable.loading1_image), 100);
animation.addFrame(getResources().getDrawable(R.drawable.loading2_image), 100);
animation.addFrame(getResources().getDrawable(R.drawable.loading3_image), 100);
animation.setOneShot(false);// Sets whether the animation should play once or repeat

ImageView anim = (ImageView) findViewById(;
anim.setBackgroundDrawable(animation);// Set the background to a given Drawable Starter());
/* a thread is being created */
Thread splashThread = new Thread() {
public void run()
int waited = 0;

while (_active && (waited < _splashTime))
sleep(1000);//waiting time
if (_active)
waited += 1000;
} catch (InterruptedException e)

finally {

//the next activity is called

Intent info = new Intent(SplashScreenActivity.this,SoundActivity.class
class Starter implements Runnable {
public void run() {
animation.start(); // Starts the animation

• Create a Project .
• Create the xml file.
• Add some images into your drawable folder.
• Add the above code in your Activity class.
• Run the application.

Screen shots of the animation :

splashanim1 splashanim2


6 thoughts on “Frame animation in android

  1. Magnificent goods from you, man. I’ve understand your stuff previous to and you’re just extremely magnificent. I actually like what you’ve acquired here, really like what you’re stating and the way in which you say it. You make it entertaining and you still care for to keep it wise. I can’t wait to read far more from you. This is really a terrific website.

  2. Thanks for ones marvelous posting! I genuinely enjoyed reading it, you might be a great author.I will always bookmark your blog and will eventually come back later in life. I want to encourage continue your great job, have a nice weekend!

  3. I simply want to mention I am beginner to weblog and truly liked you’re blog. Likely I’m going to bookmark your site . You really come with great writings. Appreciate it for sharing your website.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s