Android-universal-image-loader-master detailed

Source: Internet
Author: User
<span id="Label3"></p><p>Android-universal-image-loader-master use<br>: Https://github.com/nostra13/Android-Universal-Image-Loader<br>Steps:<br>1), first configure the Imageloaderconfiguration this class to achieve global Imageloader implementation of the situation,<br>Application in the Configuration.<br><br>This configuration tuning is Custom. You can tune every option, your may tune some of them,<br>Or you can create the default configuration by<br>Imageloaderconfiguration.createdefault (this);<br>Method.<br>Imageloaderconfiguration.builder config = new Imageloaderconfiguration.builder (context);<br>Config.threadpriority (thread.norm_priority-2);<br>Config.denycacheimagemultiplesizesinmemory ();<br>Config.diskcachefilenamegenerator (new Md5filenamegenerator ());<br>Config.diskcachesize (50 * 1024 * 1024); MiB<br>Config.tasksprocessingorder (queueprocessingtype.lifo);<br>Config.writedebuglogs (); Remove for release app<br><br>Note: more configuration items are viewed in imageloaderconfiguration.builder.<br><br>2), Initialize global configuration<br>Initialize Imageloader with Configuration.<br>Imageloader.getinstance (). Init (config.build ());<br><br>3), Initialize the display image format Displayimageoptions settings<br>Displayimageoptions options = new Displayimageoptions.builder ()<br>. showimageonloading (r.drawable.ic_stub)<br>. Showimageforemptyuri (r.drawable.ic_empty)<br>. Showimageonfail (r.drawable.ic_error)<br>. cacheinmemory (true)<br>. Cacheondisk (true)<br>. Considerexifparams (true)<br>. displayer (new Roundedbitmapdisplayer (20))<br>. Build ();<br>4), loading the picture onto the control<br>Imageloader.getinstance (). displayimage (imageurls[position], holder.image, options,null);<br>Note: DisplayImage This method has multiple overloaded forms, depending on the Situation.<br>5) example:<br>5.1) Configure the global parameters and initialize:<br>/*******************************************************************************<br>public class Uilapplication extends application {<br>@TargetApi (build.version_codes. Gingerbread)<br>@SuppressWarnings ("unused")<br>@Override<br>public void OnCreate () {<br>If (Constants.Config.DEVELOPER_MODE && Build.VERSION.SDK_INT >= build.version_codes. Gingerbread) {<br>Strictmode.setthreadpolicy (new StrictMode.ThreadPolicy.Builder (). detectall (). penaltydialog (). Build ());<br>Strictmode.setvmpolicy (new StrictMode.VmPolicy.Builder (). detectall (). penaltydeath (). Build ());<br>}<br><br>Super.oncreate ();<br><br>Initimageloader (getapplicationcontext ());<br>}<br><br>Initializing the Imageloader global configuration<br>public static void Initimageloader (context Context) {<br>This configuration tuning is Custom. You can tune every option, your may tune some of them,<br>Or you can create the default configuration by<br>Imageloaderconfiguration.createdefault (this);<br>Method.<br>Imageloaderconfiguration.builder config = new Imageloaderconfiguration.builder (context);<br>Config.threadpriority (thread.norm_priority-2);<br>Config.denycacheimagemultiplesizesinmemory ();<br>Config.diskcachefilenamegenerator (new Md5filenamegenerator ());<br>Config.diskcachesize (50 * 1024 * 1024); MiB<br>Config.tasksprocessingorder (queueprocessingtype.lifo);<br>Config.writedebuglogs (); Remove for release app<br><br>Initialize Imageloader with Configuration.<br>Imageloader.getinstance (). Init (config.build ());<br>}<br>}<br>5.2),<br><br>public class MyActivity extends Activity {<br><br>Private Layoutinflater inflater;<br>Private Displayimageoptions options;<br>Private ListView listview;<br>string[] Imageurls = constants.images;<br><br>@Override<br>protected void OnCreate (Bundle Savedinstancestate) {<br>Super.oncreate (savedinstancestate);<br>Setcontentview (r.layout.fr_image_list);<br>Inflater=layoutinflater.from (this);<br>Init ();<br><br>listview= (ListView) Findviewbyid (android. r.id.list);<br>Listview.setadapter (new Mybaseadapter ());<br>}<br><br>Private class Mybaseadapter extends baseadapter{<br><br>@Override<br>public int GetCount () {<br>Return imageurls.length;<br>}<br><br>@Override<br>Public Object GetItem (int Position) {<br>Return imageurls[position];<br>}<br><br>@Override<br>Public long Getitemid (int Position) {<br>Return position;<br>}<br><br>@Override<br>Public View getView (int position, View convertview, viewgroup Parent) {<br>View view=convertview;<br>Viewholder holder;<br>If (convertview==null) {<br>Holder=new Viewholder ();<br>View = inflater.inflate (r.layout.item_list_image, parent, false);<br>Holder.image = (ImageView) View.findviewbyid (r.id.image);<br>Holder.text = (TextView) View.findviewbyid (r.id.text);<br>View.settag (holder);<br>}else{<br>holder= (viewholder) View.gettag ();<br>}<br>Holder.text.setText ("Item" + (position + 1));<br>Instantiate Imageloader and load pictures<br>Imageloader.getinstance (). displayimage (imageurls[position], holder.image, options,null);<br> <br>Return view;<br>}<br>}<br><br>View Cache Object<br>private Static Class Viewholder {<br>TextView text;<br>ImageView image;<br>}<br><br>private void init () {<br>options = new Displayimageoptions.builder ()<br>. showimageonloading (r.drawable.ic_stub)<br>. Showimageforemptyuri (r.drawable.ic_empty)<br>. Showimageonfail (r.drawable.ic_error)<br>. cacheinmemory (true)<br>. Cacheondisk (true)<br>. Considerexifparams (true)<br>. displayer (new Roundedbitmapdisplayer (20))<br>. Build ();<br>}<br>}</p><p><p>Android-universal-image-loader-master detailed</p></p></span>

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.