Loading the network picture in Android is a very annoying thing, there are many open-source libraries on the Internet to load the network pictures, it is very convenient for us to load the network pictures. Here I mainly introduce myself in the use of volley, Picasso, universal-imageloader Some of the use of sentiment. And the most basic usage introduction.
1.android-volley
- Set up a picture source for ImageView
- ImageView is a ImageView instance
- The second parameter of Imageloader.getimagelistener is the default picture resource ID
- The third parameter is the resource ID at the time of the request failure and can be specified as 0
- Imagelistener listener = Imageloader.getimagelistener (ImageView, Android. R.drawable.ic_menu_rotate, Android. R.drawable.ic_delete);
- Mimageloader.get (URL, listener);
Copy Code
Volley provides a new control Networkimageview to replace the traditional ImageView, the Picture property of this control can be
- Mimageview.setimageurl (URL, imageloader)
Copy the code to set it. Furthermore, this control automatically cancels the network request when it is detach from the parent control, that is, without worrying about the lifecycle of the associated network request.
- Mimageloader = new Imageloader (Mrequestqueue, New Bitmaplrucache ());
- .... ...
- if (holder.imagerequest! = null) {
- Holder.imageRequest.cancel ();
- }
- Holder.imagerequest = Mimageloader.get (Base_ur + Item.image_url, Holder.imageview, r.drawable.loading, R.DRAWABLE.ERROR);
Copy Code
Summary: If your project is a relatively small project, or not very high project, processing relatively simple can use the library, this library is a Google I/O release of an open source library. The use of this library in the image processing, not provide any image processing operations, personal feeling this library is mainly in the network data connection is better, in the picture processing is not perfect, strong.
2.Picasso
The use of Picasso loading network images is simple and requires a single line of code to be done.
- Picasso.with (context). Load (URL). Resize (). Centercrop (). into (ImageView)
Copy Code
Picasso has the following characteristics:
- Handles ImageView recycling in adapter and cancels the download process that has reclaimed ImageView
- Complete complex image transformations with minimal memory, such as converting downloaded images to rounded corners
- Automatically add disk and memory caches
Summary: If you have a project inside, there are some specific requirements for the picture, it is recommended to use this library, but this library when you need to do something specific to the picture, such as loading rounded rectangle picture, cropping the picture as a circle, you need to write some of the operation, if the foundation is not good enough to feel very difficult. There is this library we can only see the results, unable to care about the download process of the picture.
3.universal-imageloader
- First, configure the Imageloaderconfiguration class to implement the global Imageloader implementation. You can choose to initialize the class in application.
- When using Imageloader for picture loading, first instantiate the Imageloader
Summary: This library has a detailed configuration to load the network pictures. Can be based on personal preference, some configuration and so on. And can realize the picture downloading process monitoring. and can support the picture after the download is complete, display a circle or rounded rectangle picture.
Android-universal-image-loader,android-volley and Picasso three big Android open source components load network picture advantages and disadvantages comparison