Use imageloader of Volley framework to load network images

Source: Internet
Author: User

The volley framework has also done a lot of work in requesting network images, providing several methods. This article describes how to use imageloader to load network images.
Imageloader is implemented using imagerequest internally. Its constructor can input an imagecache cache parameter to implement the image cache function. It can also filter duplicate links to avoid repeated requests.
The following is how imageloader loads images:
Public void displayimg (view) {imageview = (imageview) This. findviewbyid (R. id. image_view); requestqueue mqueue = volley. newrequestqueue (getapplicationcontext (); imageloader = new imageloader (mqueue, new bitmapcache (); imagelistener listener = imageloader. getimagelistener (imageview, R. drawable. default_image, R. drawable. default_image); imageloader. get ("http://developer.android.com/images/home/aw_dac.png", listener); // specifies the maximum width and height allowed by the image // imageloader. get ("http://developer.android.com/images/home/aw_dac.png", listener, 200,200 );}
Create an imagelistener instance using the imageloader. getimagelistener () method and add the listener and image URL to the imageloader. Get () method to load the network image.

The following is a cache class implemented using lrucache:
Public class bitmapcache implements imagecache {private lrucache <string, bitmap> cache; Public bitmapcache () {cache = new lrucache <string, bitmap> (8x1024*1024) {@ override protected int sizeof (string key, Bitmap bitmap) {return bitmap. getrowbytes () * bitmap. getheight () ;};}@ override public bitmap getbitmap (string URL) {return cache. get (URL) ;}@ override public void putbitmap (string URL, Bitmap bitmap) {cache. put (URL, bitmap );}}

Finally, do not forget to add the network access permission to the androidmanifest. xml file.
 
<Uses-Permission Android: Name = "android. Permission. Internet"/>

Sample source code:
Http://download.csdn.net/detail/gaolu/7815527

Use imageloader of Volley framework to load network images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.