Drawable Animation in Android

Animation by displaying each drawable from sequence of drawables for certain duration can be achieved in Android using AnimationDrawable. AnimationDrawable takes a list of drawables and displays them one by one for the specified duration.

First you need to define AnimationDrawable. AnimationDrawable can be defined in xml or code. Then you need to call start() method on AnimationDrawable to start the animation. You can start AnimationDrawable in response to user events or without user interaction. Make sure that start() method is called after AnimationDrawable is attached to window. If you want to display animation without user interaction, call start() method in onWindowFocusChanged() method in your activity.

You can configure drawable animation to run only once by setting oneshot property to true. For each frame in the drawable animation, you can set duration in milliseconds frame displays.

You can configure drawable animation in xml by using animation-list element and animation-list contains list of drawable items as shown in below example. You need to create drawable animation xml file in res/drawable folder. You can add drawable items in the code also by calling addFrame() method of AnimationDrawable.

Drawable Animation Example

android drawable animation example

Drawable Animation Code


 package com.zoftino.animation;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

public class DrawableAnimationActivity extends AppCompatActivity {
    AnimationDrawable drawableAnimation;

    protected void onCreate(Bundle savedInstanceState) {

        ImageView imgView = (ImageView) findViewById(R.id.imgview);

        drawableAnimation = (AnimationDrawable) imgView.getBackground();

    public void startAnimation(View view){

    public void stopAnimation(View view){

Activity layout




Animation list