user3693698
user3693698

Reputation: 67

Showing gifs in android

I am using a normal image view to display images from my server, now I want to show gif animations but have no idea how to do it, can you please help me?

Upvotes: 2

Views: 2459

Answers (2)

Ismael Di Vita
Ismael Di Vita

Reputation: 1836

You can use a library called Glide, check this link https://github.com/bumptech/glide

Add the dependency to your build.gradle

dependencies {
  compile 'com.github.bumptech.glide:glide:3.7.0'
  compile 'com.android.support:support-v4:19.1.0'
}

To show the gif in your ImageView use this sample:

ImageView imageView = (ImageView) findViewById(R.id.imageView);
Glide.with(context)
    .load(imageUrl)
    .asGif()
    .crossFade()
    .into(imageView);

Upvotes: 2

Dmitriy Puchkov
Dmitriy Puchkov

Reputation: 1601

I use this library in my project https://github.com/koral--/android-gif-drawable
It works perfectly in RecyclerView.

Using library is very simple, just add

 compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.16'

to your build.gradle file and use it in you layout like this

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

Or you can use it from code like this:

GifDrawable gifFromPath = new GifDrawable( "/path/anim.gif" );

Upvotes: 4

Related Questions