Android Development (45 Blogs) Become a Certified Professional

Frame Animation in Android

Last updated on Feb 09,2021 22K Views

It’s been said that Animation is the state of being alive. Something that gives you an illusion. In mobile application development too this has got its own significance. In this blog we will go through, how to use Frame Animation in android and the art of illusion.

In Android Frame Animation, you will be 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, one needs to have set of images, which describes a motion.

Android logo-EdurekaNow let’s move on and see how to implement this using frame animation

Step 1- Create a drawable folder

Within it create an animation_list.xml file.
It includes :
A list of items that has the addresses of the frame images.

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="" android:oneshot="false">
<item android:drawable="@drawable/blank" android:duration="210" />
<item android:drawable="@drawable/logo" android:duration="210" />
<item android:drawable="@drawable/logo1" android:duration="210" />
<item android:drawable="@drawable/logo2" android:duration="210" />
<item android:drawable="@drawable/logo3" android:duration="210" />
<item android:drawable="@drawable/logo4" android:duration="210" />
<item android:drawable="@drawable/logo5" android:duration="210" />
<item android:drawable="@drawable/logo6" android:duration="210" />
<item android:drawable="@drawable/logofinal" android:duration="210" />

Step 2: Create an activity_main.xml file
It Includes : An Image View


<span style="font-size: 13px; text-align: center;">Here we are done with the xml part, see the image below for reference :-</span>
<p style="text-align: center;"><a href="" target="_blank"><img class="aligncenter size-full wp-image-2382" title="XML part in Frame animation" alt="XML part in Frame animation" src="" width="845" height="603" /></a></p>
<h2><span style="font-size: large;"><strong>Step 3- Outside the onCreate method :</strong></span></h2>
<strong></strong>Declare the Image View and Animation Drawable

[code lang="java"]
// Declaring an Image View and an Animation Drawable
ImageView view;
AnimationDrawable frameAnimation;

Step 3- Inside the OnCreate method:

  • Typecast the Image view
  • Typecast the Animation Drawable
  • Set the drawable background on the image view
// Typecasting the Image View
view = (ImageView) findViewById(;

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

// Typecasting the Animation Drawable
frameAnimation = (AnimationDrawable) view.getBackground();

Step 4- After the onCreate method :

The animation should only run when it is in focus that is when it is visible to the user. Hence define this method after the onCreate method.

// Called when Activity becomes visible or invisible to the user
public void onWindowFocusChanged(boolean hasFocus) {
      if (hasFocus) {
	// Starting the animation when in Focus
	} else {
        // Stoping the animation when not in Focus

So the final result will look like this :-
Frame animation in android Frame animation in android Frame animation in android

[dl url=”#” class=’eModal eModal-20′ title=”Download Code” desc=”” type=”” align=”” for=”download”]

Stay tuned for more tutorials to learn how to create Android widgets! Happy Learning!

Got a question for us? Please mention it in the comments section and we will get back to you.

edurekaRelated Posts:

Start your training on Android Development


Join the discussion

Browse Categories

webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

Frame Animation in Android