Search code examples
javaandroidgifandroid-glide

How to show gif on Glide


I want to show gif on Glide error() in recycler Adapter. how should I do that?

I want to show a picture in Glide, and when the internet will be disconnected, I'll show a Gif, but Glide Gif will not show. here is my glide code that just shows loading_back.gif and didn't show connection_fail.gif .

 RequestOptions options = new RequestOptions()
            .centerCrop()
            .placeholder(R.drawable.static_place_holder)
            .error(R.drawable.connection_fail)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .priority(Priority.HIGH);

    Glide.with(context)
            .load(items.get(pos).getLinks())
            .apply(options)
            .thumbnail(Glide.with(context).load(R.drawable.loading_back))
            .thumbnail(Glide.with(context).load(R.drawable.connection_fail))
            .into(holder.imageView);

Solution

  • From This and this questions.

    build.gradle(app-level)

    dependencies {
      implementation 'com.github.bumptech.glide:glide:4.14.2'
      annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
    }
    

    Use of Glide.

    Glide.with(context)
        .load(imgUrl)
        .asGif()
        .placeholder(R.drawable.img)
        .crossFade()
        .into(imageView);