Android Universal-image-loader-1.9.4.jar-based image caching.
Jar package can be downloaded to the Web, which encapsulates the network to get pictures and in the mobile phone to open the cache area of the method, only need to do the following configuration operation can be used.
It works like this, if the phone is connected to a network, then the component gets the picture from the network and writes the picture to the cache, and if the network is not connected, it gets the loaded picture from the cache area and displays it.
Here is how to configure and use it specifically:
1: Add the jar package and add the dependencies.
2: Configure Universal-image-loader, Code:
Importcom. Inext. Test. Volleytest. R;Importcom. Nostra13. Universalimageloader. Cache. Disc. Impl. Unlimiteddiskcache;Importcom. Nostra13. Universalimageloader. Cache. Disc. Naming. Md5FileNameGenerator;Importcom. Nostra13. Universalimageloader. Core. Displayimageoptions;Importcom. Nostra13. Universalimageloader. Core. Imageloader;Importcom. Nostra13. Universalimageloader. Core. Imageloaderconfiguration;Importcom. Nostra13. Universalimageloader. Core. Assist. Imagescaletype;Importcom. Nostra13. Universalimageloader. Core. Download. Baseimagedownloader;/** * Created by Administrator on 2016/5/6. * *public class Imgloaderutil {private static displayimageoptions options = new Displayimageoptions. Builder()//Picture displayed on download. showimageonloading(R. Mipmap. IC_launcher)//Download error when the picture is displayed. Showimageonfail(R. Mipmap. IC_launcher)//The picture displayed when the download is empty. Showimageforemptyuri(R. Mipmap. IC_launcher)//Storage and HDD. Cacheinmemory(true). Cacheondisk(true). Bitmapconfig(Bitmap. Config. ARGB_8888)//scale type. Imagescaletype(Imagescaletype. Exactly_stretched)//Reset. resetviewbeforeloading(true). Build();public static void display (String url,imageview ImageView) {//This imageloader is not imageloader under volley. getinstance(). DisplayImage(url,imageview,options);}public static void Clear () {Imageloader. getinstance(). Cleardiskcache();Imageloader. getinstance(). Clearmemorycache();} public static void Imageloader (context context) {Imageloaderconfiguration configuration = new I Mageloaderconfiguration. Builder(context). Denycacheimagemultiplesizesinmemory()//thread pool recommended size is3 . ThreadPoolSize(3)//Thread Priority. ThreadPriority(Thread. NORM_priority)//Memory Cache size. Memorycachesize(int) (Runtime. GetRuntime(). MaxMemory()/8))///HDD Cache size. Diskcachesize( -*1024x768*1024x768)//Encryption method. Diskcachefilenamegenerator(New Md5filenamegenerator ())//default settings. Defaultdisplayimageoptions(displayimageoptions. Createsimple()). Imagedownloader(New Baseimagedownloader (context,50000,50000))//Unlimited cache. DiskCache(New Unlimiteddiskcache (fileuitlity. getinstance(context). MakeDir("Imgcache"))). Build();Imageloader. getinstance(). Init(configuration);}}
3: Call:
//初始化ImgLoaderUtil.imageLoader(context);//传入图片地址和要显示的imageview,系统会自动处理网络与缓存并加载显示图片ImgLoaderUtil.display(url, img);
Android Picture Cache