在后台下载图像,同时显示列表视图 [英] Downloading images in background while showing the listview

查看:117
本文介绍了在后台下载图像,同时显示列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的列表我展示这些图像的所有URI的数组。
现在我想在后台运行一个线程从网上得到这个图像并存储在SD卡上。
所以,当我点击列表中的,而不是从网络获取特定的元素,应该在新的活动SD卡读取。

I have an array of all the URIs of the images which I am showing in a List. Now I want to run a thread in background which gets this images from web and store them on the SD card. So when I click a particular element in the list instead of fetching from web it should fetch from the SD card in the new activity.

我如何做到这一点?

推荐答案

您的可能的尝试使用我的懒惰,可绘制框架(GPL V3行货):

You could try using my lazy-drawables framework (GPL v3 licensed):

https://github.com/rtyley/lazy-drawables

-unfortunately它不是完全准备好生产还没有,但其中的东西它试图处理:

-unfortunately it's not quite ready for production yet, but among the things it attempts to handle:


  • 图像资源的背景(非UI线程)加载

  • 缩放位图的高效的缓存 - 对于您正在下载一个大的上下的形象,要显示它几百次在ListView什么
  • 小图标格式用例
  • 使用的透明度,我的意思是...

  • background (non-UI-thread) loading of image resources
  • efficient caching of scaled bitmaps - for the use-case where you're downloading a single big-ish image, and want to show it hundreds of times in a smaller icon format in a listview or something
  • transparency of use, by which I mean...

...一旦你有一个懒惰的抽拉会话建立,填充图像的看法是一样容易:

...once you have a lazy-drawable session set up, populating an image view is as easy as:

Drawable avatarDrawable = imageSession.get(someUserIdentifier); // doesn't block
imageView.setImageDrawable(avatarDrawable);

您不要的保养的,它可能会立即返回你一个正常的bitmapdrawable,或者可能催生一个异步任务,并返回一个占位符绘制 - 提拉会自动更新,它的主机的ImageView当异步任务已经完成了。

You don't care that it may have immediately returned you a normal bitmapdrawable, or possibly spawned an async task and returned a placeholder drawable - the drawable will update itself and it's host ImageView when the async task has completed.

这是理论呢。这似乎八九不离十,有点工作至今,但有时自发UI更新不会发生......不知道为什么: - }

That's the theory anyway. It seems to sorta-kinda work so far, but sometimes that spontaneous UI update doesn't happen... not sure why :-}

这篇关于在后台下载图像,同时显示列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆