Should I stagger a large number of image load call

2019-04-17 13:17发布

问题:

I have a ListView with ~100 large images. Each image is about 640.640 jpg and is shown 1/2 screen size. Typical gallery.

I am currently loading the images using the wonderful universal-image-loader-1.9.2.

ParseFile photoFile = p.getParseFile("imageFile");
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage( photoFile.getUrl(), theImageView );

Now, you get a bit of stutter on the ListView, when they are loading.

Now, coincidentally, I had the phone on a very slow WiFi network. IN FACT, IT WAS SMOOTH AS SILK.

At first, I couldn't work out why the sudden improvement! Serendipity!

In fact then, in that situation: is it worth staggering the calls to load the images?

So, I could leave 0.1" between each call, for example.

Or indeed, should I just do them one follows the other maybe?!

What's the deal there? Do all android engineers do this all the time? Cheers!

I've already applied all the other classical techniques I have googled up for buttery smooth ListView scrolling. Cheers

(Note that I have tried a number of systems to load the images, doesn't make a difference, it's not an issue with Universal Image Loader, which rocks.)


ashishduh, here's the code from getView ... as you see, it's trivial.

(note - setting the size makes no difference. if i try it with say 500.500 fixed, it's the same)

...
v.someTextView.setText(blah);
v.someTextView.setText(blah);

// and now the big image
if (p.containsKey("imageFile"))
    {
    // this cell has a big image

    v.mainImage.setVisibility(View.VISIBLE);
    ParseFile photoFile = p.getParseFile("imageFile");

    // ...using p.getNumber("imageWidth").floatValue(); and height
    // from the cloud, calculate needed width/height on the phone...

    v.mainImage.getLayoutParams().width = Math.round(desiredGlassWidth);
    v.mainImage.getLayoutParams().height = Math.round(desiredGlassHeight);

    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.displayImage( photoFile.getUrl(), v.mainImage );
    }
else
    {
    // this pcell has no big image
    v.mainImageIV.setVisibility(View.GONE);
    }
...

回答1:

For the record for anyone googling here ...

I just tried Picasso ... per the suggestion in the comment (thanks)

Really, it's fantastic. Only Volley would be better.

Picasso works so well, my question about staggering image calls is pointless.

http://square.github.io/picasso/

Hope it helps someone!

Any better answers, post 'em here for points!


PS1 an important point is that Picasso has a "fetch" command, which is a pre-warm. You can use this for even greater results, in some case.

PS2 as I mention above, the plain fact is the only thing better than Picasso, is moving to Volley. Hope it helps someone.