如何在Glide中将交叉渐变动画添加到GenericRequestBuilder [英] How to add crossfade animation to GenericRequestBuilder in Glide

查看:260
本文介绍了如何在Glide中将交叉渐变动画添加到GenericRequestBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此构建器加载图像

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?

我需要一个自定义的ResourceDecoder,因为对于某些型号我必须加载带有透明度的webp,所有Android版本都不支持。

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

所以我的问题是如何将crossfadeAnimation返回给我的GenericRequestBuilder?

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

推荐答案

不幸的是,没有内置的方法来交叉淡入淡出的位图。但是,您可以使用自定义 BitmapImageViewTarget ,并在<$ c $中使用 TransitionDrawable c> onResourceReady()交叉淡入淡出。如果你想避免在缓存资源时应用交叉淡入淡出,你也可以在 onResourceReady 中执行相同的操作。 github.io/glide/javadocs/360/com/bumptech/glide/request/RequestListener.html\"rel =nofollow> RequestListener 将为您提供该信息。

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.

Glide使用的代码在内部应用交叉淡入淡出也可能有所帮助。

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

此外还有 TransitionDrawable 仅适用于 Drawables ,您需要将位图包装在 BitmapDrawable 首先。

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

这篇关于如何在Glide中将交叉渐变动画添加到GenericRequestBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆