How to add crossfade animation to GenericRequestBuilder in Glide

你说的曾经没有我的故事 提交于 2020-01-02 08:58:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30081212/how-to-add-crossfade-animation-to-genericrequestbuilder-in-glide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!