Glide: How can I get drawable from glide? I want to use those drawables in Viewpager.

Created on 26 Dec 2015  路  6Comments  路  Source: bumptech/glide

question

Most helpful comment

@Ashish2000L have you read https://github.com/bumptech/glide/issues/843#issuecomment-167317760 ?
Have you Googled "glide background"?
e.g. https://stackoverflow.com/a/38025862/253468 (do not use the accepted highest voted answer, it leads to memory problems)
Maybe check out this one too https://github.com/bumptech/glide/issues/938
Working example https://github.com/TWiStErRob/glide-support/tree/master/src/glide3/java/com/bumptech/glide/supportapp/github/_938_background

All 6 comments

Please give a much more detailed description; my blind response is:

  • ViewPager can hold Views, not Drawables
  • ImageViews are Views designed to display Drawables
  • Glide.with(...).load(...).into(iv) loads Drawables

Hi, thanks for the quick response. I have list of image urls. I am trying to download those images as bitmap converting into drawable. And sending array of drawable to PagerAdapter. I am creating image view dynamically. and using drawable from the array passed earlier.

Ah you want to preload the images and then use ImageView.setImageDrawable in the adapter... I greatly advise against doing this as the whole point of the adapter loses its benefits. You can use Glide within PagerAdapter just after you created the ImageView. Many people already have problems with normal ViewPager usage (search the Glide issues), because they quickly run out of memory. If you load all pages at once you'll likely run into this as well.

If you really want to do it you can load into a SimpleTarget and do whatever you want wih the resource you get (try .load() or .load().asBitmap() to see which one fits your use better). Just remember that once you start using custom targets you may need to Glide.clear them at the appropriate time to prevent OOM. If you use Fragment/Activity in Glide.with it may be freed for you automatically.

thanks TWiStErRob. Your solution worked like a charm. Saved my day. Thanks again. :)

Is there anyway I can get the Drawable from glide as i have to set background of the layout using
relativelayout.setbackground(Drawable)

@Ashish2000L have you read https://github.com/bumptech/glide/issues/843#issuecomment-167317760 ?
Have you Googled "glide background"?
e.g. https://stackoverflow.com/a/38025862/253468 (do not use the accepted highest voted answer, it leads to memory problems)
Maybe check out this one too https://github.com/bumptech/glide/issues/938
Working example https://github.com/TWiStErRob/glide-support/tree/master/src/glide3/java/com/bumptech/glide/supportapp/github/_938_background

Was this page helpful?
0 / 5 - 0 ratings