Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't Glide load an image from resource ID to my ImageView?

I've got all of the images I need for my app, and I'm trying to speed it up and make it silky smooth, so I have been using Glide to load the images and it works in other areas of my app but not in my viewpager.

In my fragment I'm trying to load my image like so

Glide.with(this).load(R.drawable.my_drawable).into(myImageView);

and nothing happens or appears and I don't get an exception or any sort of error message from Glide.

like image 924
Jacob Collins Avatar asked Jun 04 '15 20:06

Jacob Collins


People also ask

How do you get pictures off of Glide?

To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView.

How do you load a drawable image with Glide?

into(myImageView); Load method of Glide also accept drawable object as a parameter to load image. You just have to get the drawable object from your drawable image and pass it to the load method.


3 Answers

Tobias Reich's way generates a bunch of warning logs cause load url is "". If you don't want warning logs,

Try this:

int drawableIdentifier = activity.getResources().getIdentifier("my_drawable_image_name", "drawable", activity.getPackageName());
Glide.with(activity)
     .load(drawableIdentifier)
     .into(imageView);
like image 184
Joonsoo Avatar answered Oct 22 '22 01:10

Joonsoo


I know this question is long since closed but I found a good solution for this by using the placeholder or error image instead. So you might try

Glide.with(<<MyActivity>>)
    .load("")
    .placeholder(<<myDrawable>>)
    .into(imageView);

Not sure this is what you wanted but if there are others having the same issue, at least this seems to work with a minimum of work. :)

like image 33
Tobias Reich Avatar answered Oct 22 '22 01:10

Tobias Reich


Check out the Debugging and Error Handling wiki page to enable logging. That should tell you if the load is failing and why.

If you see no error logs, it's possible that your View doesn't have a size, either because its size is 0, or because it hasn't gone through layout (visibility set to View.GONE etc). If so, you can test check by adding a call to override() with any valid width and height (try 400, 400 or something just to test).

If calling override() fixes the issue, take a look at your xml and see if you can change your view to either have a fixed size, or to at least eventually end up with a valid size. If all else fails, you can always call override() with Target.SIZE_ORIGINAL as the width and height.

like image 5
Sam Judd Avatar answered Oct 22 '22 02:10

Sam Judd