2

I'm using picasso to load images in my recycler view adaper but it is taking to much time to load image. Here is my call to load image with picasso.

Picasso.with(hostActivity).load("ImageUrl").fit().centerCrop().into(holder.ImageView);

If I do same thing with asynctask task, image loaded instantly.

Am I doing any thing wrong?

Thanks.

Asad
  • 357
  • 1
  • 7
  • 15
  • You most likely want to do that inside an AsyncTask. Otherwise you may freeze the UI or cause your application to skip frames. I don't know why this is happening, but always use AsyncTask for anything that implies loading any files / using internet – Chaoz Mar 09 '16 at 14:39
  • Picasso's load function is already async. – Asad Mar 09 '16 at 15:09

1 Answers1

2

fit() needs to wait for the size of the ImageView to be determined before it can size the image to match, and the size can't be calculated until the end of the layout pass. You might get quicker results by using resize() if you are able to predict reasonable width and height values.

You might also want to look at the Glide library as it takes a different approach to caching that can be quicker than Picasso in some cases, for example instead of caching full size images it caches the resized ones. However, there are many pros and cons to both libraries; although the syntaxes are very similar, some things that work in Picasso will not work in Glide, and vice versa.

Lorne Laliberte
  • 6,261
  • 2
  • 35
  • 36