Picasso: A One-Line Image Loader

Here is another must-have library for your project: Picasso. This library, developed by Square, handles all image loading and caching process by itself. What we need to do is just writing the following one line of code to load an image from a URL into an ImageView:

You can use it wherever you want. One of the great features of Picasso is that if you use it inside your adapter, it automatically cancels previous downloads when reuse is detected.

To be able to download images from the Internet, you should not forget to add the following permission to your manifest file:

Another thing you can do with Picasso is setting placeholder images for loading and error cases:

Picasso is not just for downloading images online. You can also load images from your project resources, assets, or device storage as follows:

To be able to use Picasso in your project, the dependency you need to add to your module-level “build.gradle” file is the following:

If ProGuard is enabled for your project, you also need to add the following rule to your ProGuard file:

All you can achieve with Picasso can be found at http://square.github.io/picasso and https://github.com/square/picasso.

Leave a Reply

Your email address will not be published. Required fields are marked *