Frame animation is explained below using a example that uses different loading images to creating a animation which continues for the specified time. 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 not started in OnCreate(), but 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 :