Mike Knoop
Mike Knoop

Reputation: 506

How do I best optimize Picasso in a GridView?

I'm using Picasso (2.5.2) to load local content:// images into a 3-column GridView via an adapter.

Picasso
    .with(mContext)
    .load(mCameraImages.getUris().get(position))
    .error(android.R.drawable.ic_dialog_alert)
    .fit()
    .centerCrop()
    .into(view);

In my particular case, mCameraImages is a just a list of URIs, coming out of the local mediaStore.

I'm finding that when I load the GridView, Picasso always fetches the images from the disk (blue debug indicator) and not memory.

This is expected but I'd like to optimize the UX by loading thumbnails or images faster.

The "performance" is particular poor if you scroll the GridView down and have to wait for ~seconds for the disk fetch to complete.

What methods could I try to optimize Picasso loading so that local content can be displayed as quick as an app like QuickPic?

Here is my reduced adapter code (it is very simple).

Upvotes: 4

Views: 1626

Answers (1)

fida1989
fida1989

Reputation: 3249

Try using Glide. It's supposed to be much faster and memory-efficient than Picasso. Also code is similar to Picasso, so you don't need much change in code.

Sample Code:

Glide.with(mContext)
    .load(mCameraImages.getUris().get(position))
    .error(android.R.drawable.ic_dialog_alert)
    .centerCrop()
    .into(view);

Check this Glide vs Picasso article to know detailed differences between the two.

Also check this Improving Performance with the ViewHolder Pattern to know about ViewHolder and implement that in your adapter to increase performance.

Upvotes: 6

Related Questions