9

I want to show the image using Glide animation. I'm downloading this image from the server. The animation is working fine when it downloads from the server but it's not working when the image is taken from Glide cache

requestOptions.skipMemoryCache(true);
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);

Please check my code below

RequestOptions requestOptions = new RequestOptions();
requestOptions.timeout((int) NetworkParam.CONNECTION_TIME_OUT);
requestOptions.placeholder(R.drawable.img_blue_shirt);
requestOptions.priority(Priority.HIGH);
requestOptions.signature(new ObjectKey(String.valueOf(imgName)));
//requestOptions.skipMemoryCache(true);
requestOptions.diskCacheStrategy(DiskCacheStrategy.NONE);

//requestOptions.error(R.drawable.img_blue_shirt);
try {
    Glide.with(imageView.getContext().getApplicationContext())
         .load(imgUrl)
         .transition(GenericTransitionOptions.with(R.anim.anim_slide_in_left))
         .apply(requestOptions)
         .into(imageView);
} catch (Exception ex) {
    ex.printStackTrace();
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
Sumit Bandekar
  • 410
  • 5
  • 10

4 Answers4

13

According to the documentation here, in Glide v4 you can implement and apply a custom TransitionFactory.

For always crossfading, in Kotlin you can:

  1. Implement the TransitionFactory interface
class DrawableAlwaysCrossFadeFactory : TransitionFactory<Drawable> {
  private val resourceTransition: DrawableCrossFadeTransition = DrawableCrossFadeTransition(300, true) //customize to your own needs or apply a builder pattern
  override fun build(dataSource: DataSource?, isFirstResource: Boolean): Transition<Drawable> {
    return resourceTransition
  }
}
  1. Apply it as a transition
GlideApp.with(this)
  .load(url)
  .transition(DrawableTransitionOptions.with(DrawableAlwaysCrossFadeFactory()))
  .into(image)
tudor
  • 478
  • 4
  • 12
7

To apply image change transition in glide 4.10 use

Glide.with(this).load(artwork)
                            ..transition(DrawableTransitionOptions.withCrossFade())
                            .into(playerBackground);
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Vikash Sharma
  • 539
  • 8
  • 13
  • The question is about animation on cached images, and this solution doesn't help with them. – Daniel Aug 26 '20 at 10:52
1

By default, Glide will not animate the image when loading it. If images are cached on disk, Glide will animate. To change that, define a custom TransitionFactory and pass it in with DrawableTransitionOptions.

For an example implementation, see the cross fade factory: https://github.com/bumptech/glide/blob/master/library/src/main/java/com/bumptech/glide/request/transition/DrawableCrossFadeFactory.java

Asteroid
  • 718
  • 7
  • 21
0

yes I got my answer here we cant apply animation on cached image in glide for more info please check below link

https://bumptech.github.io/glide/doc/transitions.html

Sumit Bandekar
  • 410
  • 5
  • 10