How to play gif in android from url?

user3606902 picture user3606902 · Jan 2, 2016 · Viewed 11.8k times · Source

I want to play animated gif from url in android app like imgur app. Imagur is superb and very fast. I am loading gif with webview but its not up to the mark.

Answer

Anggrayudi H picture Anggrayudi H · Jan 2, 2016

You can use Glide to play gif on ImageView. So, let's add it to your app's gradle:

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.android.support:support-v4:23.1.1'
}

Then, create an ImageView:

<ImageView
    android:id="@+id/imageView"
    android:contentDescription="@string/content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

In your activity:

Glide  
    .with(context) // replace with 'this' if it's in activity
    .load("http://www.google.com/.../image.gif")
    .asGif()
    .error(R.drawable.error_image) // show error drawable if the image is not a gif
    .into(R.id.imageView);

For more information, open this post Glide — Displaying Gifs & Videos.