1

I am working on an application that lets the user assign images to people and then view the images by the person's name. What I am currently doing is that when a person is clicked on, the all of that person's images will be loaded into their individual ImageViews. This works fine when loading three or four images, but when 20+ are involved, things start to get a little laggy.

So, my question is: How can I efficiently load these images from files without completely lagging out the application?


Things I have thought about:

  1. A preloader that loads all the images from all the people before starting up the main application. A problem would occur if one of the files were removed.
  2. Having a mini-preloader to load all of the images before displaying them.
  3. Loading the images without a loader when the user clicks on the person.
4

1 回答 1

4

如果您希望您的应用程序保持可扩展性(以数百张图像为轮流),在应用程序启动之前将它们全部加载是不可行的。

您看到应用程序滞后的原因很可能是有限的硬盘带宽(可能需要进行分析)。您可以做一些事情来改善图像加载(例如使用优化的图像格式/存储图像的缩小版本等),但在某些时候您总是会从磁盘加载内容。

1)我建议您创建一个由 anImageView和 a组成的自定义节点ProgressIndicator。让用户知道正在加载其他图像。

2)有限数量的工作线程加载图像以避免在等待磁盘时过度阻塞

3) 尽可能预加载和缓存图像。SoftReferences这是使用实际上是一个好主意的少数情况之一。

于 2013-06-09T21:24:22.120 回答