3

I've been using Picasso's library to load images into my gridview in my application and it works and looks exactly as I'd like. But users are telling me that the images are loading very slowly. I know that this is because of poor network speed and Picasso is loading my full images which are very big and then resizing them to fit my image view. So I tried using glide which loads the images in almost twice the speed but on some images it's not keeping the structure like Picasso does. For example Picasso loading images looks like

this

Whilst glide loading them has different states here's what it loads initially

first state

and then after scrolling it looks like

this

and then eventually after lots of scrolling it looks like

this

I am pretty confident that this is due to my images sizes all being different and also it seems that making my placeholder image a different size has an effect but what I want to know is how do I get glide to keep its initial state, or how do I get Picasso to load quicker? I've heard lowering the color format from 888 to 565 has a dramatic effect, can anybody lend me there two cents? Thanks for any and all suggestions

EDIT

this is my imageview

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:id="@+id/imageView"/>

this is how i was calling picasso

                 Picasso.with(getActivity())
                .load(mThumbIds[position])
                .placeholder(R.drawable.placeholder)
                .fit()
                .into(imageView);

        return imageView;

and this is how i am now calling glide

                 Glide.with(getActivity())
                .load(mThumbIds[position])
                .asBitmap()
                .placeholder(R.drawable.placeholder)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .fitCenter()
                .error(R.drawable.ic_photos)
                .into(imageView);

         return imageView;

and if it matters this is my gridview

    <GridView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="5dp"
    android:id="@+id/gridview"
    android:numColumns="2"
    android:gravity="center"
    android:drawSelectorOnTop="true"
    android:listSelector="@drawable/ripple"
    android:stretchMode="columnWidth"
    >
Fathima km
  • 2,539
  • 3
  • 18
  • 26
Martin Seal
  • 616
  • 2
  • 14
  • 32
  • So Glide is keeping the aspect ratios from the images and that's not what you want? Can you include the Picasso code you were using and the Glide code you're using now and the XML you use for each item (particularly the `ImageView` part)? – ianhanniballake Aug 16 '15 at 19:35
  • @ianhanniballake yeah thats a much better description than what i gave glide is keeping the aspect ratio ive added the relevant code snippets and may end up changing the title of the question also ive tried playing with scaletypes on the image view and with glides centercrop methods but to no avail – Martin Seal Aug 16 '15 at 20:22

1 Answers1

5

By default, Glide will attempt to keep the aspect ratio of the images. When you use fitCenter(), this implies that you want the whole image visible and centered within the available area. Switching to centerCrop() would be the first step in making sure the image fills both the height and width available to it.

However, you are also running into a longstanding issue with GridView: it assumes all columns have the same height. Yet, you use wrap_content for your ImageView's height, causing each element to get resized differently based on the incoming height (remember, to Glide's perspective, you said your ImageView can be as tall as it needs to be!).

If you have a dominant aspect ratio (say, 16:9), you could use a fixed aspect ratio view such as this AspectRatioImageView which would always use the same height based on the width of the column (set by your GridView). Another, more complicated, option is to switch to RecyclerView and use a StaggeredGridLayoutManager, which would allow you to keep the aspect ratio of each image and stagger the rows, ensuring that each image fills the space and keeps its aspect ratio.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Okay that makes perfect sense so at a guess as jake Wharton helps with Picasso this is probably built in to it? So I'd be better off trying to get Picasso to run lighter – Martin Seal Aug 16 '15 at 21:42
  • If you haven't seen it already when Google search, [this Glide comparison with Picasso blog post](http://www.inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google) is very well done. – ianhanniballake Aug 16 '15 at 22:16
  • So it looks like there is no setdecodeformat equivalent for picasso – Martin Seal Aug 16 '15 at 22:43