2

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?

user3693698
  • 69
  • 2
  • 9

2 Answers2

4

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" );
Dmitriy Puchkov
  • 1,530
  • 17
  • 41
2

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);
Ismael Di Vita
  • 1,806
  • 1
  • 20
  • 35