Android-universal-image-loader-master detailed

Source: Internet
Author: User

Android-universal-image-loader-master use
: Https://github.com/nostra13/Android-Universal-Image-Loader
Steps:
1), first configure the Imageloaderconfiguration this class to achieve global imageloader implementation of the situation,
Application in the configuration.

This configuration tuning is custom. You can tune every option, your may tune some of them,
Or you can create the default configuration by
Imageloaderconfiguration.createdefault (this);
Method.
Imageloaderconfiguration.builder config = new Imageloaderconfiguration.builder (context);
Config.threadpriority (thread.norm_priority-2);
Config.denycacheimagemultiplesizesinmemory ();
Config.diskcachefilenamegenerator (New Md5filenamegenerator ());
Config.diskcachesize (50 * 1024 * 1024); MiB
Config.tasksprocessingorder (QUEUEPROCESSINGTYPE.LIFO);
Config.writedebuglogs (); Remove for release app

Note: More configuration items are viewed in Imageloaderconfiguration.builder.

2), initialize global configuration
Initialize imageloader with configuration.
Imageloader.getinstance (). Init (Config.build ());

3), initialize the display image format Displayimageoptions settings
Displayimageoptions options = new Displayimageoptions.builder ()
. showimageonloading (R.drawable.ic_stub)
. Showimageforemptyuri (R.drawable.ic_empty)
. Showimageonfail (R.drawable.ic_error)
. Cacheinmemory (True)
. Cacheondisk (True)
. Considerexifparams (True)
. Displayer (New Roundedbitmapdisplayer (20))
. build ();
4), loading the picture onto the control
Imageloader.getinstance (). DisplayImage (Imageurls[position], holder.image, options,null);
Note: DisplayImage This method has multiple overloaded forms, depending on the situation.
5) Example:
5.1) Configure the global parameters and initialize:
/*******************************************************************************
public class Uilapplication extends application {
@TargetApi (build.version_codes. Gingerbread)
@SuppressWarnings ("unused")
@Override
public void OnCreate () {
if (Constants.Config.DEVELOPER_MODE && Build.VERSION.SDK_INT >= build.version_codes. Gingerbread) {
Strictmode.setthreadpolicy (New StrictMode.ThreadPolicy.Builder (). Detectall (). Penaltydialog (). build ());
Strictmode.setvmpolicy (New StrictMode.VmPolicy.Builder (). Detectall (). Penaltydeath (). build ());
}

Super.oncreate ();

Initimageloader (Getapplicationcontext ());
}

Initializing the Imageloader global configuration
public static void Initimageloader (context context) {
This configuration tuning is custom. You can tune every option, your may tune some of them,
Or you can create the default configuration by
Imageloaderconfiguration.createdefault (this);
Method.
Imageloaderconfiguration.builder config = new Imageloaderconfiguration.builder (context);
Config.threadpriority (thread.norm_priority-2);
Config.denycacheimagemultiplesizesinmemory ();
Config.diskcachefilenamegenerator (New Md5filenamegenerator ());
Config.diskcachesize (50 * 1024 * 1024); MiB
Config.tasksprocessingorder (QUEUEPROCESSINGTYPE.LIFO);
Config.writedebuglogs (); Remove for release app

Initialize imageloader with configuration.
Imageloader.getinstance (). Init (Config.build ());
}
}
5.2),

public class MyActivity extends Activity {

Private Layoutinflater Inflater;
Private displayimageoptions options;
Private ListView ListView;
string[] Imageurls = constants.images;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (r.layout.fr_image_list);
Inflater=layoutinflater.from (this);
Init ();

listview= (ListView) Findviewbyid (Android. R.id.list);
Listview.setadapter (New Mybaseadapter ());
}

Private class Mybaseadapter extends baseadapter{

@Override
public int GetCount () {
return imageurls.length;
}

@Override
Public Object getItem (int position) {
return imageurls[position];
}

@Override
public long getitemid (int position) {
return position;
}

@Override
Public View GetView (int position, View Convertview, ViewGroup parent) {
View View=convertview;
Viewholder Holder;
if (convertview==null) {
Holder=new Viewholder ();
View = Inflater.inflate (R.layout.item_list_image, parent, false);
Holder.image = (ImageView) View.findviewbyid (r.id.image);
Holder.text = (TextView) View.findviewbyid (R.id.text);
View.settag (holder);
}else{
Holder= (Viewholder) View.gettag ();
}
Holder.text.setText ("Item" + (position + 1));
Instantiate Imageloader and load pictures
Imageloader.getinstance (). DisplayImage (Imageurls[position], holder.image, options,null);

return view;
}
}

View Cache Object
private Static Class Viewholder {
TextView text;
ImageView image;
}

private void init () {
options = new Displayimageoptions.builder ()
. showimageonloading (R.drawable.ic_stub)
. Showimageforemptyuri (R.drawable.ic_empty)
. Showimageonfail (R.drawable.ic_error)
. Cacheinmemory (True)
. Cacheondisk (True)
. Considerexifparams (True)
. Displayer (New Roundedbitmapdisplayer (20))
. build ();
}
}

Android-universal-image-loader-master detailed

Related Article

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.