请尝试以下代码,是很适合我。
在oncreate中初始化imageloader类。
you can change the config param if you want.
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.appicon_).resetViewBeforeLoading(true).cacheOnDisc(true)
.imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
.displayer(new FadeInBitmapDisplayer(300)).build();
File cacheDir = StorageUtils.getCacheDirectory(mContext);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext)
.memoryCacheExtraOptions(480, 800)
// default = device screen dimensions
.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75, null)
// .taskExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
// .taskExecutorForCachedImages(AsyncTask.THREAD_POOL_EXECUTOR).threadPoolSize(3)
// default
.threadPriority(Thread.NORM_PRIORITY - 1)
// default
.tasksProcessingOrder(QueueProcessingType.FIFO)
// default
.denyCacheImageMultipleSizesInMemory().memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
// default
.memoryCacheSize(2 * 1024 * 1024).discCache(new UnlimitedDiscCache(cacheDir))
// default
.discCacheSize(50 * 1024 * 1024).discCacheFileCount(100)
.discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
.imageDownloader(new BaseImageDownloader(mContext)) // default
.defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
.build();
if (imageLoader.isInited()) {
} else {
imageLoader.init(config);
}
加载图像鉴于
imageLoader.displayImage(url, img, options, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
看到这个问题https://github.com/nostra13/Android-Universal-Image-Loader/issues/541 –
@ QadirHussain - 我已经通过它...只有无用的评论der ..:! – jigar