Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

android - Getting Picasso to pre-fetch forthcoming images

I'm using Picasso with a GridView, loading 200 images over the network. Right now it looks like Picasso is not triggering an image load over the network until the image starts to come into view on the screen.

Is there a way to have Picasso pre-fetch the next N images in the list so that the experience is better? I am using an Adapter to put the images into the Gridview.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I am prefetching images into a cache very successfully using Picasso like so:

if (BuildConfig.DEBUG) {
     Picasso.with(getApplicationContext()).setIndicatorsEnabled(true);
     Picasso.with(getApplicationContext()).setLoggingEnabled(true);
}
for (Article article : articleList) {
     ArrayList<String> images = article.getImages();
     for (String url : images) {
          if (!TextUtils.isEmpty(url)) {
               Picasso.with(getApplicationContext())
                    .load(url)
                    .resizeDimen(R.dimen.article_image_preview_width, R.dimen.article_image_preview_height)
                    .centerCrop()
                    .fetch();
          }
     }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...