Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do my images shrink after loading with glide library

Hi I'm populating a gridview with glide image loader library when they first get called into my fragment they look like this perfect But after scrolling up and down they are resized and look like this too small Is this something I'm doing with my gridview, the glide library, or is it something else like my placeholder image? on the second screenshot If I press on an image it lights up to show it is in actual fact filling that whole space, anyone know what I'm doing wrong here? I've tried changing the call in glide playing with centercrop and such but it seems to make no difference, I'm not sure how I would work out the width and height of each cell, any suggestions welcome

EDIT here is how im calling glide

   Glide.with(getActivity())
                .load(mThumbIds[position])
                .placeholder(R.drawable.placeholder)
                .error(R.drawable.ic_drawer)
                .centerCrop()
                .override(500,300)
                .into(imageView);
like image 595
Martin Seal Avatar asked Aug 03 '15 11:08

Martin Seal


People also ask

How do I change the width and height of a picture in Glide?

Add an explicit width or height to the ImageView by setting layout_width=500dp in the layout file. Call . override(width, height) during the Glide load and explicitly set a width or height for the image such as: GlideApp.

What is Glide override?

Image Resizing with override(x, y) Glide automatically limits the size of the image it holds in cache and memory to the ImageView dimensions.

How do I reduce the size of a photo in Glide?

If a loaded image happens to be smaller than the ImageView, Glide will unnecessarily expand original bitmap to match the size of the target view. One way to prevent it is to set scaleType=”centerInside” in the ImageView. That way loaded image won't expand beyond the original size.

What is Glide library?

Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application. It provides animated GIF support and handles image loading/caching.


1 Answers

Actually you have to give fix width and height to your image container(ImageView).

<ImageView
    android:id="@+id/channelImage"
    android:layout_width="65dp"
    android:layout_height="65dp"
    android:layout_centerHorizontal="true"
    android:layout_margin="10dp"
    android:src="@drawable/sama" />

Then when you call glide you have to override your width and height dynamically with override method. This is maximum Width and height for you container.

Glide.with(getActivity())
                    .load("your url")

                    .placeholder(R.drawable.tv2v_icon)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .fitCenter()
                    .override(500,500)
                    .into(channelImage);

hope this can help you.

like image 193
Saad Bilal Avatar answered Sep 19 '22 21:09

Saad Bilal