bumptech / glide

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

Image space occupied but not Image is shown #130

Closed harshavardhands closed 10 years ago

harshavardhands commented 10 years ago

In wiki (wiki/Transformations) given as "You can also apply either of the default transformations if you're loading Bitmaps or GIFs" // For gifs:

Glide.with(yourFragment)
    .load(yourUrl)
    .asGif()
    .fitCenter()
    .into(yourView);

Space is occupied, but image is not shown...

My Code:

String url = "http://upload.wikimedia.org/wikipedia/commons/2/2b/Seven_segment_display-animated.gif";
imageView2 = (ImageView) findViewById(R.id.imageView2);
Glide.with(this).load(url).asGif().into(imageView2);

By using listener it worked out.

Glide.with(this).load(url).asGif().listener(new MyRequestListener()).into(imageView2);
sjudd commented 10 years ago

Hmm I'm not totally sure what the issue is. What is MyRequestListener? How does it relate to transformations?

I can show a list containing the gif you provided a link for by replace simply replacing the load line in the giphy sample with this:

    Glide.with(activity)
                    .load("http://upload.wikimedia.org/wikipedia/commons/2/2b/Seven_segment_display-animated.gif")
                    .asGif()
                    .fitCenter()
                    .into(gifView);
harshavardhands commented 10 years ago

MyRequestListener is my custom class, implementing RequestListener<T, GlideDrawable>. In onResourceReady method, by type casting I am able to see the gif image

public boolean onResourceReady(GlideDrawable resource, T model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            ImageView view = ((ImageViewTarget<?>) target).getView();
            GifDrawable drawable = (GifDrawable) resource;
            view.setBackgroundDrawable(drawable);
            return false;
        }

Without this listener and with the below code, I am not able to see the image.

Glide.with(activity)
.load("http://upload.wikimedia.org/wikipedia/commons/2/2b/Seven_segment_display-animated.gif")
.asGif()
.fitCenter()
.into(gifView);
sjudd commented 10 years ago

Can you show the xml or code for your image view? What are it's width and height? If it's easy for your to reproduce can you add a test case or a sample activity? It definitely shouldn't be necessary to set the drawable as the background drawable.

Also if you change view.setBackgroundDrawable() to view.setImageDrawable() in your listener, do you see the image?

harshavardhands commented 10 years ago

Created a test project https://github.com/harshavardhands/GlideTest

If view.setImageDrawable() set then image is not shown to UI but when I used view.setBackgroundDrawable() i am able to view it.

sjudd commented 10 years ago

Hmm I'm still not able to reproduce the problem with your sample app. I wonder if this is version or device specific. What device/android os version are you using to test?

My guess is that it's related to you using wrap_content to describe the width/height of your view. Glide wants to resize your images so wrap_content is hard for it to handle. It should still show the image, but you may want to consider switching to using a more concrete size (a warning is also logged about this).

Screenshot from a nexus 7 2 on 4.4 below:

screenshot_2014-09-12-15-20-34

harshavardhands commented 10 years ago

Checked in Genymotion emulator: Virtual device Samsung galaxy S2-4.1.1

vova-bilous commented 10 years ago

Have the same issue.

If view.setImageDrawable() set then image is not shown to UI but when I used view.setBackgroundDrawable() i am able to view it.

sjudd commented 10 years ago

Sorry for the delay, I reproduced this and I'll have a fix up shortly. Thank you @harshavardhands for the sample project and following up with a specific version of Android, hugely helpful! Thanks @vladimir-belous as well for pinging the issue.

Turns out it's a bug (or at least a difference in behavior) between Android 4.1 and 4.4. In 4.4 setVisible is always called on Drawables during ImageView#setImageDrawable, but not in 4.1.

vova-bilous commented 10 years ago

Thank you, very fast fix. One more question, When you going to push version with fix to maven repo?

sjudd commented 10 years ago

I added a target milestone, but may do another dot release before then, in which case I'll update the issue. You can join the mailing list if you want to keep more careful track of releases and dates.

For now you can always depend on the snapshot version which is built and pushed after each successful build on master:

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
    compile 'com.github.bumptech.glide:glide:3.4.+'
}