Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 935
DaBeeeenster Avatar asked Jul 22 '14 08:07

DaBeeeenster


People also ask

How will you load an image into an imageView from an image URL using Picasso and display a custom image if there is an error while loading the image?

Image loading using Picasso is very easy, you can do it like this way Picasso. get(). load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details.

Why use Picasso library?

Picasso is open source and one of the widely used image download libraries in Android. It is created and maintained by Square. It is among the powerful image download and caching library for Android. Picasso simplifies the process of loading images from external URLs and displays them on your application.


Video Answer


1 Answers

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();
          }
     }
}
like image 83
Bill Mote Avatar answered Oct 04 '22 01:10

Bill Mote