Korniltsev Anatoly
Korniltsev Anatoly

Reputation: 3686

How to add crossfade animation to GenericRequestBuilder in Glide

I load images with this builder

Glide.with(ctx)
    .using(new FileModelLoader(downlaoder), FilePath.class)
    .from(FileReference.class)
    .as(Bitmap.class)
    .decoder(new FilePathDecoder(ctx))
    .diskCacheStrategy(DiskCacheStrategy.NONE);

The problem is: there is no crossfade animation. So how do i return it?

I need a custom ResourceDecoder because for some models I have to load webp with transparancy which is not supported on all android versions.

So my question is how do I return crossfadeAnimation to my GenericRequestBuilder?

Upvotes: 2

Views: 1618

Answers (1)

Sam Judd
Sam Judd

Reputation: 7387

Unfortunately there isn't a built in way to cross fade Bitmaps. You can however, use a custom BitmapImageViewTarget, and use a TransitionDrawable in onResourceReady() to cross fade. If you want to avoid applying the cross fade when the resource is cached, you can alternatively do the same thing in onResourceReady in a RequestListener which will give you that information.

The code Glide uses to apply cross fades internally may also be helpful.

Also since TransitionDrawable only works on Drawables, you will need to wrap your Bitmap in a BitmapDrawable first.

Upvotes: 5

Related Questions