Andre Perkins
Andre Perkins

Reputation: 7800

Image appears stretched after loading Placeholder image via Glide?

I am trying to use Glide to load a few images in a Listview. The image loads correctly if I don't use a placeholder while loading the image. However, when I attempt to set a placeholder, the image that I am loading from over the network appears stretched. This only occurs in instances where the placeholder image is used. If I were to leave the screen and return (so that no placeholder image is loaded) the image then appears correctly.

Here is my simple Glide implementation:

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

Upvotes: 4

Views: 3422

Answers (3)

Abhi
Abhi

Reputation: 2285

I know I'm answering pretty late, but this is how it helped me:

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

Use dontAnimate(), it worked for me. Hope it helped :)

Upvotes: 9

Wess
Wess

Reputation: 779

I had the same problem where if the placeholder is smaller than the image being fetched, the image will be stretched when loaded onto the ImageView. I tried everything I could think of and the following worked perfectly for me:

I have the following attributes set on my ImageView:

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

And used Glide in the following way:

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

The key things to note here is the adjustViewBounds attribute on the ImageView set to true and most importantly the .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) - this will force Glide to use the original size of the image.

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

Upvotes: 5

HourGlass
HourGlass

Reputation: 1830

I guess that, you have given both Imageview widht and height as Wrap_content. So whenever Glide load Images some Images may be larger in size, so it's streteched.

Try this out.

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

Upvotes: 1

Related Questions