【问题标题】:ListView- Async task- Loading imagesListView- 异步任务- 加载图片
【发布时间】:2015-09-28 18:53:13
【问题描述】:

在我的应用程序中,我需要显示存储在外部存储目录中的图像。我用这些图像填​​充列表视图。但是,如果有太多图像说,> 10,应用程序内存不足。我现在明白我应该实现一个异步任务来实现这一点。有人可以帮助我如何做到这一点。我应该在 LisviewAdapter.java 或 Activity.java 中调用 Async 类吗?任何示例都会很有帮助。在此先感谢。

【问题讨论】:

  • 发布你的日志...发布一些代码,这样我们就可以真正检查出什么问题了。另外,图片有多大?
  • @MarianoZorrilla:图像是从设备相机以 8MP 捕获的。因此,它们大约为 2MB 及以上。 'Asynctask' 是将图像加载到列表视图中的正确方法吗?请建议
  • 问题不在于...您不需要异步任务...您需要的是像 picasso 这样的库来获取图像并调整它们的大小(仅用于显示)。 8MP 对于 Android 来说太多了,无法在单个图像视图中显示它。

标签: android listview android-asynctask android-imageview


【解决方案1】:

要优化它,我最好建议你使用 Picasso 从 URL 加载图像的库。

特点是:

Handling ImageView recycling and download cancelation in an adapter.
Complex image transformations with minimal memory use.
Automatic memory and disk caching.

检查这个:http://square.github.io/picasso/

【讨论】:

    【解决方案2】:

    你必须使用 LazyLoading 机制来避免内存问题。 Picasso 是 android 完成此类任务的绝佳库。只需在适配器中添加该行,而不是直接将位图设置为 imageview:

    Picasso.with( context ).load( new File(...)).into( imageView3 );
    

    您也已将它们添加到依赖列表中的 build.gradle 文件中:

    compile 'com.squareup.picasso:picasso: 2.5.2 '
    

    【讨论】:

      猜你喜欢
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-06
      • 2012-12-20
      • 2023-04-07
      • 1970-01-01
      • 2011-10-04
      相关资源
      最近更新 更多