Adding gif image in an ImageView in android

Kamalone picture Kamalone · Jun 30, 2011 · Viewed 315.6k times · Source

I added an animated gif image in an imageView. I am not able to view it as a gif image. No animation is there. It's appearing just as a still image. I would like to know how can i show it as a gif image.

Answer

Armando Esparza García picture Armando Esparza García · Feb 8, 2016

In your build.gradle(Module:app), add android-gif-drawable as a dependency by adding the following code:

allprojects {
    repositories {
       mavenCentral()
    }
}

dependencies {
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.+'
}


UPDATE: As of Android Gradle Plugin 3.0.0, the new command for compiling is implementation, so the above line might have to be changed to:

dependencies {
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.17'
}

Then sync your project. When synchronization ends, go to your layout file and add the following code:

<pl.droidsonroids.gif.GifImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/gif_file"
/>

And that's it, you can manage it with a simple ImageView.