package com.example.lianxi12; import android.app.Application; import android.content.Context; import android.graphics.Bitmap; import android.os.Handler; import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator; import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; import com.nostra13.universalimageloader.core.assist.ImageScaleType; import com.nostra13.universalimageloader.core.assist.QueueProcessingType; import com.nostra13.universalimageloader.utils.StorageUtils; import java.io.File; public class MyApplication extends Application { private Context context; @Override public void onCreate() { super.onCreate(); context = this; images(); } public void images() { File cacheDir = StorageUtils.getCacheDirectory(context); // ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .diskCacheExtraOptions(480, 800, null) // () .threadPoolSize(3) // default .threadPriority(Thread.NORM_PRIORITY - 2) // default .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) // .memoryCacheSize(2 * 1024 * 1024) // .memoryCacheSizePercentage(13) // default .diskCacheSize(50 * 1024 * 1024) // 50 Mb sd() .diskCacheFileCount(100) // // defaultHASHCODEUILMD5(new Md5FileNameGenerator()) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) .writeDebugLogs() // debug log // .build(); //imageLoader ImageLoader.getInstance().init(config); } public static DisplayImageOptions getOptions(){ DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(R.mipmap.ic_launcher) // .showImageForEmptyUri(R.mipmap.ic_launcher) // Uri .showImageOnFail(R.mipmap.ic_launcher) // .resetViewBeforeLoading(false) // default .delayBeforeLoading(0) // .cacheInMemory(true) // default .cacheOnDisk(true) // default SD .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default .bitmapConfig(Bitmap.Config.ARGB_8888) // default // .displayer(new SimpleBitmapDisplayer()) // default new RoundedBitmapDisplayer(20) .handler(new Handler()) // default .build(); return options; } }
文章来源: ImageLoader