Android Universal ImageLoader多次加载相同的图像

时间:2016-11-11 06:05:54

标签: android universal-image-loader

我正在使用UniversalImageLoader来加载图像。但我面临的问题是多次加载相同的图像.Below是日志输出。

logcat的:

11-11 11:10:21.342 26932-26932/com.example.sabudaniel61.ktdc D/ImageLoader: Load image from memory cache [http://loc8app.com/ktdcapp.in/ktdc/app/img/Aranya%20Nivas/room3.jpg_480x340]
11-11 11:10:21.342 26932-29175/com.example.sabudaniel61.ktdc D/ImageLoader: ImageAware is reused for another image. Task is cancelled. [http://loc8app.com/ktdcapp.in/ktdc/app/img/Aranya%20Nivas/room1.jpg_480x340]
11-11 11:10:21.342 26932-29175/com.example.sabudaniel61.ktdc D/ImageLoader: ImageAware is reused for another image. Task is cancelled. [http://loc8app.com/ktdcapp.in/ktdc/app/img/Aranya%20Nivas/room2.jpg_480x340]

MainActivity.java:

ImageLoaderConfiguration config=new ImageLoaderConfiguration.Builder(getApplicationContext()).memoryCacheExtraOptions(480,800).threadPoolSize(5).threadPriority(Thread.NORM_PRIORITY-3).denyCacheImageMultipleSizesInMemory().memoryCacheSize(2*104*1024).memoryCacheSizePercentage(13).diskCacheSize(50*1024*1024).diskCacheFileCount(100).imageDownloader(new BaseImageDownloader(getApplicationContext())).defaultDisplayImageOptions(DisplayImageOptions.createSimple()).writeDebugLogs().build();
ImageLoader.getInstance().init(config);

HotelsFragment.java:

   DisplayImageOptions options=new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.ktdclogonew).showImageForEmptyUri(R.drawable.ktdclogonew).showImageOnFail(R.drawable.ktdclogonew).cacheInMemory(true).cacheOnDisk(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565).build();
for(int i=0;i<Images.getInstance().AranyaGll.length;i++){
imageView=(ImageView) view.findViewById((Integer) imgs_ids.get(i));
 ImageLoader.getInstance().displayImage(Images.getInstance().AranyaGll[i],imageView,options);
 }

1 个答案:

答案 0 :(得分:1)

尝试替换它:

DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.ktdclogonew).showImageForEmptyUri(R.drawable.ktdclogonew).showImageOnFail(R.drawable.ktdclogonew).cacheInMemory(true).cacheOnDisk(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565).build();
    for (int i = 0; i < Images.getInstance().AranyaGll.length; i++) {
        imageView = (ImageView) view.findViewById((Integer) imgs_ids.get(i));
        ImageLoader.getInstance().displayImage(Images.getInstance().AranyaGll[i], imageView, options);
    }

有了这个:

DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.ktdclogonew).showImageForEmptyUri(R.drawable.ktdclogonew).showImageOnFail(R.drawable.ktdclogonew).cacheInMemory(true).cacheOnDisk(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565).build();
    for (int i = 0; i < Images.getInstance().AranyaGll.length; i++) {
        //This is the change I made.
        ImageView imageView = (ImageView) view.findViewById((Integer) imgs_ids.get(i));
        ImageLoader.getInstance().displayImage(Images.getInstance().AranyaGll[i], imageView, options);
    }

注意:我将图片视图设为本地