Reputation: 81
Using the thumbnail(0.5f)
should reduce the size of the image to 50% its original but it doesn't.
Consider the following code.
Glide.with(context).load(imgUrl)
.thumbnail(0.5f) //Make this work.
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
I have tried removing the other methods like crossFade()
, diskCacheStrategy()
etc. to see if they were creating some problem, but no it still doesn't resize the image.
I have also tried to load the view dynamically through code instead of using an xml file, it still doesn't resize.
Full disclosure, i am doing all of this inside a fragment.
I don't know what it is i am doing that is wrong. Hope someone helps.
Upvotes: 1
Views: 2345
Reputation: 1329
It seems your code for the Glide module is correct, But there might be a error with "context", Check weather the context is null. Or if not try to use getContext() method inside the fragment as follow.
Glide.with(getContext()).load(imgUrl)
.thumbnail(0.5f)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
for more reference try Glide documentation. Hope this will help.
Upvotes: 0
Reputation: 3976
Use override(int,int)
method for resize image dynamically. glide generates a new bitmap with width and height mentioned in override(w,h) and then load the image into ImageView
. You can use fitCenter()
to align the image. You can also use diskCacheStrategy()
.
Glide.with(context)
.load(imgUrl)
.override(800, 400)
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView)
Hope it will help you!!
Upvotes: 1