Image appears stretched after loading Placeholder image via Glide?

I am trying to use Glide to upload multiple images to a Listview. The image loads correctly if I do not use a placeholder when loading the image. However, when I try to set the placeholder, the image that I download from the network looks stretched. This only happens when a placeholder image is used. If I have to leave the screen and return (so that the image with the sample is not loaded), the image will be displayed correctly.

Here is my simple Glide implementation:

Glide.with(context)
                .load(url)
                .placeholder(R.drawable.empty_logo)
                .error(R.drawable.error)
                .into(imageView);
+4
source share
3 answers

, , :

Glide.with(context).load(url).placeholder(R.drawable.empty_logo).dontAnimate().into(imageView);

dontAnimate(), . , :)

+8

, Wrap_content. , Glide load Images , .

.

<ImageView
android:width="match_parent"
android:height="50dp"
android:scaleType="fitXY"/>
+1

, , , , ImageView. , , :

, ImageView:

<ImageView
    android:id="@+id/my_image_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"/>

Glide :

Glide.with(myImageView.getContext())
            .load(imageUrl)
            .placeholder(R.drawable.placeholder)
            .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
            .into(myImageView);

The key points here are the adjustViewBounds attribute in ImageView set to true, and most importantly .override (Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) - this will force Glide to use the original image size.

You can also specify the size in pixels in .override () , but remember to specify the correct ScaleType for your ImageView, otherwise it will also stretch the image.

+1
source

Source: https://habr.com/ru/post/1628303/


All Articles