Creating Frame Animations in Android

This example explains step by step process to create Frame Animations in Android.

An animation created by moving an object little-by-little over several consecutive frames. In Android, we can create Frame Animation by swapping frames repeatedly, so that it appears continuous to the human eye and we feel that it is animated.

Frame is referred to an image. So to implement frame by frame animation in android, we needs to have set of images, which describes a motion. Now let’s move on and see how to implement this using frame animation.

Refer following steps for creating a frame animation in android.

  1. Prepare a series of PNG images with the individual frames of your animation. Add the PNG images to your project’s drawable folder.

  1. Prepare an frame_animation_list.xml for animation. This will go into the anim or drawable folder of your project, and in our example the file is named frame_animation_list.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android=""

    <item android:drawable="@drawable/frame1" android:duration="210" />
	<item android:drawable="@drawable/frame2" android:duration="210" />
	<item android:drawable="@drawable/frame3" android:duration="210" />
	<item android:drawable="@drawable/frame4" android:duration="210" />
	<item android:drawable="@drawable/frame5" android:duration="210" />
	<item android:drawable="@drawable/frame6" android:duration="210" />
	<item android:drawable="@drawable/frame7" android:duration="210" />
	<item android:drawable="@drawable/frame8" android:duration="210" />
	<item android:drawable="@drawable/frame9" android:duration="210" />
	<item android:drawable="@drawable/frame10" android:duration="210" />

  1. Create a layout file with an ImageView. This will show the animation
<RelativeLayout xmlns:android=""
    android:layout_height="match_parent" >

        android:adjustViewBounds="true" />

  1. Animate pragmatically
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends Activity {

	private AnimationDrawable frameAnimation;
	private ImageView view;

	protected void onCreate(Bundle savedInstanceState) {


		// Type casting the Image View
		view = (ImageView) findViewById(;

		// Setting animation_list.xml as the background of the image view

		// Type casting the Animation drawable
		frameAnimation = (AnimationDrawable) view.getBackground();

	public void onWindowFocusChanged(boolean hasFocus) {
		if (hasFocus) {
			// Start animation when in Focus
		} else {
			// stop animation when not in Focus

A blogger, speak, author, a bit of tech freak and a software developer. He is a thought leader in the fusion of design and mobile technologies. He has over 8 years of experience in developing rich mobile applications in Android, HTML5, Xamarin and PhoneGap.

  • Pallavi Choudhary

    I want to switch between two inflated relative layouts can this be done using frame animation

  • MG Infotech

    Thank youuu