bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.67k stars 6.12k forks source link

Placeholder is visible under transparent images when using cross fade #2017

Closed minas90 closed 7 years ago

minas90 commented 7 years ago

Hi there, I have code like this

            GlideApp.with(context)
                    .load(url)
                    .transition(withCrossFade())
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .placeholder(R.color.placeholder)
                    .into(imageView);

I guess after it loads transparent image, instead of replacing placeholder, it puts image in front of placeholder.

christopherperry commented 7 years ago

This is expected behavior. See https://github.com/bumptech/glide/issues/1990

minas90 commented 7 years ago

Hi Christopher, Thanks for reply!

Can you please provide an example. Not sure where should I pass DrawableCrossFadeFactory from the doc.

        DrawableCrossFadeFactory factory =
                new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true).build();
TWiStErRob commented 7 years ago

@minas90 "you can enable cross fades by adjusting the options in DrawableCrossFadeFactory and passing the result into transition()." - at the end of http://bumptech.github.io/glide/doc/transitions.html#cross-fading-with-placeholders-and-transparent-images

so it should be new DrawableTransitionOptions().withCrossFade(factory) and this options object goes into http://bumptech.github.io/glide/javadocs/400/com/bumptech/glide/RequestBuilder.html#transition-com.bumptech.glide.TransitionOptions-

But since you're using GlideApp I think you can skip the options and replace withCrossFade() in OP with your factory.

minas90 commented 7 years ago

Hi Robert, I tried to replace withCrossFade() with factory as I understood from the doc, but transition accepts TransitionOptions and complains about DrawableCrossFadeFactory.

screen shot 2017-06-09 at 7 10 51 am

And as withCrossFade is static, my final code is as follows

            DrawableCrossFadeFactory factory =
                    new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true).build();

            GlideApp.with(context)
                    .load(url)
                    .transition(withCrossFade(factory))
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .placeholder(R.color.placeholder)
                    .into(imageView);

I think it will be great to write about it in the doc and maybe add some code snippet as it's not so straightforward to understand until you dig into the source.

timrijckaert commented 7 years ago

I had a similar problem. The solution was indeed harder than expected to find.

Thanks for this.

dennisrufigill commented 5 years ago

Hello, Thanks alot for the solution. Really helped me with my code.

jagadishnallappa commented 3 years ago

@minas90 "you can enable cross fades by adjusting the options in DrawableCrossFadeFactory and passing the result into transition()." - at the end of http://bumptech.github.io/glide/doc/transitions.html#cross-fading-with-placeholders-and-transparent-images

so it should be new DrawableTransitionOptions().withCrossFade(factory) and this options object goes into http://bumptech.github.io/glide/javadocs/400/com/bumptech/glide/RequestBuilder.html#transition-com.bumptech.glide.TransitionOptions-

But since you're using GlideApp I think you can skip the options and replace withCrossFade() in OP with your factory.

This worked. Thanks a lot mate. Cheerio!

StevenZhangHl commented 3 months ago

我为什么没有withCrossFade()这个方法