Android-Universal-Image-Loader这么个好东西 ,用起来非常的方便,大家可以看Demo,里面有详细的介绍。
但在使用过程可能会报java.lang.RuntimeException: ImageLoader must be init with configuration before using(使用前要初始化)
1】只要在OnCreate方法里调用 imageLoader.init(ImageLoaderConfiguration.createDefault(MainActivity.this));
2】官网demo是初始化是在application类调用
public class MyApplication extends Application{
private static final String TAG = MyApplication.class.getSimpleName();
private static Context context;
@Override
public void onCreate() {
super.onCreate();
Logger.dout(TAG + " 应用初始化");
public static Context getContext() {
return context;
}
public static void initImageLoader(Context context) {
int memoryCacheSize = (int) (Runtime.getRuntime().maxMemory() / 8);
MemoryCacheAware<String, Bitmap> memoryCache;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
memoryCache = new LruMemoryCache(memoryCacheSize);
} else {
memoryCache = new LRULimitedMemoryCache(memoryCacheSize);
}
// This configuration tuning is custom. You can tune every option, you may tune some of them,
// or you can create default configuration by
// ImageLoaderConfiguration.createDefault(this);
// method.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.NORM_PRIORITY - 2)
.memoryCache(memoryCache)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.enableLogging() // Not necessary in common
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
}