Frame animation is explained below using a example that uses different loading images to creating a animation which continues for the specified time.

android.graphics.drawable.AnimationDrawable 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() .

Example:
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class SplashScreenActivity extends Activity
{
AnimationDrawable animation;
protected boolean _active = true;
protected int _splashTime = 5000;
@Override
public void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
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(R.id.frame_id);
anim.setBackgroundDrawable(animation);// Set the background to a given Drawable
anim.post(new Starter());

/* a thread is being created */
Thread splashThread = new Thread() {
@Override
public void run()
{
try
{
int waited = 0;

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

finally {
finish();
);

//the next activity is called

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

Steps:
• 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 :