佳婿 2015-08-28 04:01 采纳率: 0%
浏览 1785
已结题

Android imageloader 显图片间长了导致溢出

在listview 中 使用imageLoader.displayImage显示图片 内存不能释放干净,每次加载列表页面都会有1MB左右内存增长,时间长了导致溢出,试了在跳转页面时用

AnimateFirstDisplayListener.displayedImages.clear();
imageLoader.clearMemoryCache();
imageLoader.clearDiscCache();
System.gc();
释放,效果不是很理想,也试过跳转回首页后finish掉其它所有activity,参数配置也换了很多,但也没有解决问题,下面是我的imageloader具体参数配置 ,希望有经验的朋友能给些指点,谢谢。

DisplayImageOptions options = new DisplayImageOptions.Builder().
bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.showStubImage(R.drawable.no_refurbish) // 设置图片下载期间显示的图片
.showImageForEmptyUri(R.drawable.ic_empty) // 设置图片Uri为空或是错误的时候显示的图片
//.showImageOnFail(R.drawable.ic_error) // 设置图片加载或解码过程中发生错误显示的图片

.cacheInMemory(false) // 设置下载的图片是否缓存在内存中
.cacheOnDisc(true) // 设置下载的图片是否缓存在SD卡中
// .displayer(new RoundedBitmapDisplayer(20)) // 设置成圆角图片
.build();

    File cacheDir = StorageUtils.getOwnCacheDirectory(context.getApplicationContext(), "imageloader/Cache");  

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
    .threadPriority(Thread.NORM_PRIORITY-2)

    .denyCacheImageMultipleSizesInMemory()
    .memoryCacheExtraOptions(150, 150) // default = device screen dimensions

// .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
.denyCacheImageMultipleSizesInMemory()
.discCache(new UnlimitedDiscCache(cacheDir))
.discCacheSize(50 * 1024 * 1024)

.memoryCache(new FIFOLimitedMemoryCache(1000000)) // You can pass your own memory cache implementation
// .memoryCacheSize(13)
// .tasksProcessingOrder(QueueProcessingType.FIFO)
// .threadPoolSize(4)
// .threadPriority(Thread.MIN_PRIORITY + 3)
// .denyCacheImageMultipleSizesInMemory()
// .discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.writeDebugLogs() // Remove for release app
.defaultDisplayImageOptions(options)
.build();

            listview 的getview中 使用 
           imageLoader.displayImage(imageUrls[position], holder.image);
            显示图片
  • 写回答

1条回答 默认 最新

  • 吉祥如意zx 2015-08-28 08:17
    关注

    imageLoader.displayImage(imageUrls[position], holder.image,options);

    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样