Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide shrinks image on first load

When I load the image into the ImageView with Glide, it shrinks the image. When I rotate or reopen the same activity it has the right size. I already tried possible duplicate. I am already passing fix size to the ImageView inside the xml and I tried to override the size as well. centerCrop() and fitCenter() has no effect on the shrink. I also tried to debug the image size. When it is shrinked or not it returns same width and height.

View:

<ImageView
      android:id="@+id/thumbnail"
      android:layout_width="@dimen/episode_detail_img_width"
      android:layout_height="@dimen/episode_detail_img_height"
      android:layout_marginTop="@dimen/episode_detail_img_margin_top" />

Glide

Glide.with(getActivity())
            .load(url)
            .placeholder(R.drawable.thumb_placeholder)
            .centerCrop()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(thumbnail);
like image 378
parohy Avatar asked Jul 29 '16 12:07

parohy


People also ask

How do you refresh Glide?

You click sync in Glide If you are building your project in Glide and need to see the latest data from your data source, you can click the sync button.


1 Answers

I am glade you got your answer. Just for more description of your problem is :

Glide calculated your ImageView height and width before starting a load of an image but when an image gets load it replace your placeholder drawable. so if your placeholder drawable height or weight is small, Glide will render downloaded bitmap with placeholder's dimension.

So, for no lag in different screen size and layout, I advise using high dimension drawable in a placeholder.

And one more hack is that use color in a placeholder because color has no height or width, so render in the whole area of the view.

like image 111
Dharvik shah Avatar answered Sep 28 '22 03:09

Dharvik shah