Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image space occupied but not Image is shown #130

Closed
harshavardhands opened this issue Sep 11, 2014 · 10 comments
Closed

Image space occupied but not Image is shown #130

harshavardhands opened this issue Sep 11, 2014 · 10 comments

Comments

@harshavardhands
Copy link

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
Copy link
Collaborator

sjudd commented Sep 11, 2014

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
Copy link
Author

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
Copy link
Collaborator

sjudd commented Sep 12, 2014

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
Copy link
Author

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
Copy link
Collaborator

sjudd commented Sep 12, 2014

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
Copy link
Author

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

@vova-bilous
Copy link

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
Copy link
Collaborator

sjudd commented Sep 21, 2014

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.

@sjudd sjudd closed this as completed in a9d87fb Sep 21, 2014
@vova-bilous
Copy link

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

@sjudd sjudd added this to the 3.4 milestone Sep 21, 2014
@sjudd sjudd added the bug label Sep 21, 2014
@sjudd
Copy link
Collaborator

sjudd commented Sep 21, 2014

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.+'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants