In the Android development process will inevitably encounter the following situations:
1, picture asynchronous loading
2. Picture Cache
3. Picture Display
4. Other ... (Forget it)
In these cases, you may want to write a lot of code to achieve these functions, and for some novice, may write for a half day, found that the effect is not ideal, memory problems are not handled well, async also bad control (I am this). So search, found online the most popular Android image open-source framework Universal-image-loader, personally used a bit, found that it is really useful ah! A total of more than 10 lines of code will be done, mom no longer have to worry about my time to go blind to engage in eight!
Okay, here's the quick steps to use this framework:
First, add Universal-image-loader-1.9.2-with-sources.jar this jar package to the project's Libs folder. Click here to download directly!
Second, create a new class that inherits application, where the code looks like this:
public class MyApplication extends application {public void OnCreate () {super.oncreate (); Initimageloader ( Getapplicationcontext ());} public static void Initimageloader (context context) {Imageloaderconfiguration config = new Imageloaderconfiguration.builder (context). ThreadPriority (thread.max_priority). Denycacheimagemultiplesizesinmemory (). Diskcachefilenamegenerator (New Md5filenamegenerator ()). Tasksprocessingorder (Queueprocessingtype.lifo). Writedebuglogs ()//Remove for release App.build (); I Mageloader.getinstance (). init (config);}}
Note that this application class is to be noted in the application tag in Menifest! This is the following:
<application
android:name="Com.lee.example.MyApplication"
Well, add the above two steps, the basic framework environment is set up, here is how to use it to load network pictures:
Declare two objects first:
Private DisplayimageoptionsOptions;
Private ImageloaderImageloader;
They are then initialized in the constructor of the class or in the Increate method of the activity:
Imageloader = Imageloader.getinstance ();
Options =new displayimageoptions.builder ()
. showimageonloading (null)//Picture displayed during load
. Showimageforemptyuri (null)//load content empty display picture
. Showimageonfail (null)//load failed to display picture
. cacheinmemory (true). Cacheondisk (true). Considerexifparams (true)
. Bitmapconfig (Bitmap.config. rgb_565). Displayer (new Fadeinbitmapdisplayer (388)). build ();
Here's how to use:
Imageloader. DisplayImage (ImageFile,imageView, options);
Description
ImageFile: The network path of the picture (can also use the local path Oh, details of the framework of the end of the text GitHub Chinese document description)
ImageView: is the picture control ha ~
On top of that, it's so convenient!
Frame of GitHub Address: Https://github.com/nostra13/Android-Universal-Image-Loader
Small ads: Attention to the public number: "Big tabby cat", it is an intelligent chat robot, can answer a variety of questions, including query all kinds of information Oh! It can also be face recognition, just send a face photo, you can identify and reply to a variety of information Oh! It also has a lot of web games Oh! There are more exciting features in development! Let's get to the attention! ^ ^
Android Picture frame: quick use of Universal-image-loader