Universal image Loader own use of some feelings

Source: Internet
Author: User

1. The application definition of the global entry is initialized:

Imageloaderconfiguration configuration =NewImageloaderconfiguration.builder (Getapplicationcontext ()). ThreadPoolSize (3)//number of lines Cheng Chinega loaded. ThreadPriority (Thread.norm_priority-1)//default. Denycacheimagemultiplesizesinmemory ()//. MemoryCache (New Weakmemorycache ())//You can also use your own memory to cache the actual. MemoryCache (NewLrumemorycache (50 * 1024 * 1024))//You can also use your own memory cache to implement. Memorycachesize (50*1024*1024). Diskcachefilenamegenerator (NewMd5filenamegenerator ())//encrypt the URL name at the time of saving with MD5. Tasksprocessingorder (Queueprocessingtype.fifo)//Advanced First Out. diskcachesize (200 * 1024 * 1024). Defaultdisplayimageoptions (Displayimageoptions.createsimple ()). Imagedownloader (NewBaseimagedownloader (Getapplicationcontext ()))//default. Imagedecoder (NewBaseimagedecoder (true))//default//. Writedebuglogs ()//Remove for release app. Build (); //Global initialization of this configurationImageloader.getinstance (). init (configuration);

2. Display settings:

/*** options for displaying pictures, no transition time * for circle community, flash flashing when resolving a list of pictures too many*/     Public StaticDisplayimageoptions Optionswithcache =NewDisplayimageoptions.builder (). showimageonloading (R.drawable.icon_no_photo). Showimageonfail (R. Drawable.icon_no_photo). Showimageforemptyuri (R.drawable.icon_no_photo)//sets the picture to be displayed when the image URI is empty or wrong. Cacheinmemory (true). Cacheondisk (true). Bitmapconfig (Bitmap.Config.RGB_565). Considerexifparams (true)            //exactly_stretched: The picture zooms to the exact size of the target exactly: the target size of the image will be scaled down completely//In_sample_int: The image will be sampled in multiples of two times. Imagescaletype (Imagescaletype.in_sample_int). resetviewbeforeloading (false)            //. Delaybeforeloading (+)//a little delay before loading the picture will improve the smoothness of the overall slide.. Displayer (NewFadeinbitmapdisplayer (200))//whether the picture is loaded and the animation time is gradually entered. build ();

3, if the ImageView set the length of the width of the size:

Display can be used to automatically scale the image according to the size of the ImageView, saving memory:

imageloader.getinstance (). DisplayImage (Pic_url, imageview,optionswithcache);

For the ListView, the image may be duplicated by sliding too fast, which can be handled by setting tag:

 Public Static voidSetimagewithtag (FinalString Pic_url,FinalImageView imageview,context Context) {        if(Pic_url! =NULL) {String tag=(String) Imageview.gettag (); if(Tag = =NULL) {tag= ""; }            if(Pic_url.equals (Imageview.gettag ())) {return; }} String Picurl=Pic_url; if(!picurl.contains ("HTTP//") ) {Picurl= myconfig.picfirst+Picurl; }        //log.i ("main", "Loading Pic:" +pic_url);imageloader.getinstance (). DisplayImage (Picurl, ImageView, Optionswithcache); }

Settings inside the listview:

Setimageutils.setimagewithtag (picurl,holder.iv,context);

Holder.iv.setTag (picurl);

4, some pictures during the loading process of monitoring:

//load a picture of a custom configuration, Network Load Monitor, wait for the load picture to complete and then initialize to zoom outImageloader.getinstance (). DisplayImage (Picurl,mimageview, Setimageutils.optionswithcache,NewSimpleimageloadinglistener () {@Override Public voidonloadingstarted (String imageuri, view view) {Super. onloadingstarted (Imageuri, view); Utility.setloadingprogressbar (NULL, Parentview,true); } @Override Public voidOnloadingcomplete (String imageuri, view view, Bitmap loadedimage) {Super. Onloadingcomplete (Imageuri, view, loadedimage); Utility.setloadingprogressbar (NULL, Parentview,false); }        }, NewImageloadingprogresslistener () {@Override Public voidOnprogressupdate (String s, view view,intIintI1) {                //log.i ("main", "i=" +i+ ", il=" +i1);            }        });

There are mainly Imageloadinglistener (or its subclasses), and there are two kinds of imageloadingprogresslistener.

For universal image loader combination of memory, local storage two-level mechanism, to a certain extent convenient use, but there are some problems, there is a certain chance to oom, loading network pictures not fast enough.

Universal Image Loader Some of the feelings you use

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.