【问题标题】:Performance Issue loading images thumbnails in RecyclerView在 RecyclerView 中加载图像缩略图的性能问题
【发布时间】:2016-09-14 13:29:02
【问题描述】:

我正在开发一个文件管理器,当我检测到当前目录中的图像时,我想向用户显示一个缩略图。我可以做到这一点,唯一的问题是当目录中有图像时,所有 UI 都会变得缓慢和滞后。我想问一些提高性能的方法。以下是代码片段:

这里我检查文件是否为图像:

fileName = file.getName();
fileName = fileName.substring(fileName.lastIndexOf('.') + 1);
if(fileName.equals("jpg"))
         dir.add(new Item(ff.getName(), ff.length() + " Byte", date_modify, ff.getAbsolutePath(), "image_icon"));

这里是FileAdapter代码来设置recycler view行的imageView:

if(item.getImage().equals("image_icon")){
Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(item.getPath()),
                        100, 100);
holder.icon.setImageBitmap(ThumbImage);
 }

如果需要更多代码,请告诉我。

【问题讨论】:

  • 使用Glide加载图片

标签: android image performance android-bitmap


【解决方案1】:

添加依赖

compile 'com.github.bumptech.glide:glide:3.7.0'

并写在你的适配器中

Glide.with(mContext).load(imgUrl)
            .thumbnail(0.5f)
            .crossFade()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(holder.icon);

【讨论】:

  • 谢谢,现在它并不卡顿,但加载图像很慢。有没有办法让它更快?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-14
  • 2013-04-29
  • 2011-09-21
  • 2016-03-01
相关资源
最近更新 更多