Glide中如何给GenericRequestBuilder添加crossfade动画
How to add crossfade animation to GenericRequestBuilder in Glide
我用这个构建器加载图像
Glide.with(ctx)
.using(new FileModelLoader(downlaoder), FilePath.class)
.from(FileReference.class)
.as(Bitmap.class)
.decoder(new FilePathDecoder(ctx))
.diskCacheStrategy(DiskCacheStrategy.NONE);
问题是:没有交叉淡入淡出动画。
那我怎么return呢?
我需要一个自定义的 ResourceDecoder,因为对于某些模型,我必须加载具有透明度的 webp,这在所有 android 版本上都不支持。
所以我的问题是如何 return crossfadeAnimation 到我的 GenericRequestBuilder?
遗憾的是,没有内置淡入淡出位图的方法。但是,您可以使用自定义 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 来为您提供该信息。
Glide 用于 apply cross fades internally 的代码也可能有帮助。
此外,由于 TransitionDrawable
仅适用于 Drawables
,您需要先将 Bitmap
包装在 BitmapDrawable 中。
我用这个构建器加载图像
Glide.with(ctx)
.using(new FileModelLoader(downlaoder), FilePath.class)
.from(FileReference.class)
.as(Bitmap.class)
.decoder(new FilePathDecoder(ctx))
.diskCacheStrategy(DiskCacheStrategy.NONE);
问题是:没有交叉淡入淡出动画。 那我怎么return呢?
我需要一个自定义的 ResourceDecoder,因为对于某些模型,我必须加载具有透明度的 webp,这在所有 android 版本上都不支持。
所以我的问题是如何 return crossfadeAnimation 到我的 GenericRequestBuilder?
遗憾的是,没有内置淡入淡出位图的方法。但是,您可以使用自定义 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 来为您提供该信息。
Glide 用于 apply cross fades internally 的代码也可能有帮助。
此外,由于 TransitionDrawable
仅适用于 Drawables
,您需要先将 Bitmap
包装在 BitmapDrawable 中。