How to put an animated GIF in an APP on Android?

Posted on

Question :

Well, I’ve been having this problem for some time, I tried to solve using StackOverflow answers but I did not succeed.

I need to put an animated GIF image in my activity but ImageView does not play a .gif image, it just shows it as an image without animation.

Can anyone help me?

Remembering that I’m programming for Android.


Answer :

You can use lib Glide for this







If it’s in the drawable folder

            .load(R.drawable.gifanimation2) // aqui é teu gif

First context of your class, according to the url of the Gif or drawable and third your ImageView that in the case is the id of it.

Link to the link


android natively has no resource for .gif animated.
For you to do this effect we will have to have all the images of the animation available to be added in a xml .

Then create an xml named animation.xml and add this content to it:

<animation-list xmlns_android=""
id="animacao" android_oneshot="false" >
<item android_drawable="@drawable/android1" android_duration="150" />
<item android_drawable="@drawable/android2" android_duration="150" />
<item android_drawable="@drawable/android3" android_duration="150" />
<item android_drawable="@drawable/android4" android_duration="150" />
<item android_drawable="@drawable/android5" android_duration="150" />
<item android_drawable="@drawable/android6" android_duration="150" />
<item android_drawable="@drawable/android7" android_duration="150" />

And in the xml of your Activity create a ImageView

<ImageView android_layout_height="wrap_content"
    android_layout_width="wrap_content" android_id="@+id/imgAndroid"
    android_layout_gravity="center_horizontal" />

Now in your Activity class, link ImageView and create AnimationDrawable by implementing your class this way:

import android.os.Bundle;
import android.widget.ImageView;

public class Main extends Activity {
    private ImageView imgAndroid;
    private AnimationDrawable mAnimation;

public void onCreate(Bundle savedInstanceState) {

    imgAndroid = (ImageView)findViewById(;

    mAnimation = (AnimationDrawable)imgAndroid.getBackground();



And to stop the animation use: mAnimation.stop();



I had problems implementing the animated gif in my project and solved it in a very simple way:

<ImageView android_layout_height="wrap_content"
android_layout_width="wrap_content" android_id="@+id/imgAndroid"
android_layout_gravity="center_horizontal" />

I changed it to: (I removed the reference from the android image: background=”@ drawable / android1″)

<ImageView android_layout_height="wrap_content"
android_layout_width="wrap_content" android_id="@+id/imgAndroid"
android_layout_gravity="center_horizontal" />

The implementation is the same already informed:


It might help someone.


Leave a Reply

Your email address will not be published. Required fields are marked *