【发布时间】:2011-09-07 23:22:12
【问题描述】:
我正在寻找类似于 Android 的 SDWebImage 的东西。 SDWebImage 在 iOS 中的作用是这样的:
从 URL 加载图像,使用缓存,进行异步下载。
我正在为 Android 寻找类似的东西。有什么提示吗?
谢谢。
【问题讨论】:
我正在寻找类似于 Android 的 SDWebImage 的东西。 SDWebImage 在 iOS 中的作用是这样的:
从 URL 加载图像,使用缓存,进行异步下载。
我正在为 Android 寻找类似的东西。有什么提示吗?
谢谢。
【问题讨论】:
【讨论】:
在 Applidium,我们最近将 SDWebImage 移植到了 Android。它被称为 Shutterbug,它可以满足您的所有要求。
这里是项目的链接:https://github.com/applidium/Shutterbug。尽情享受吧!
【讨论】:
我在以下链接中得到了这个答案:Lazy load of images in ListView
package com.wilson.android.library;
/* 获得 Apache 软件基金会 (ASF) 的一项许可 或更多贡献者许可协议。请参阅通知文件 随本作品分发以获取更多信息 关于版权归属。 ASF 许可此文件 根据 Apache 许可证,版本 2.0( “执照”);除非合规,否则您不得使用此文件 与许可证。您可以在
处获取许可证的副本http://www.apache.org/licenses/LICENSE-2.0
除非适用法律要求或书面同意,
根据许可分发的软件在
“原样”基础,不提供任何保证或条件
种类,无论是明示的还是暗示的。请参阅许可证
特定语言管理权限和限制
根据许可证。
*/
import java.io.IOException;
public class DrawableManager {
private final Map<String, Drawable> drawableMap;
public DrawableManager() {
drawableMap = new HashMap<String, Drawable>();
}
public Drawable fetchDrawable(String urlString) {
if (drawableMap.containsKey(urlString)) {
return drawableMap.get(urlString);
}
Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
try {
InputStream is = fetch(urlString);
Drawable drawable = Drawable.createFromStream(is, "src");
if (drawable != null) {
drawableMap.put(urlString, drawable);
Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", "
+ drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", "
+ drawable.getMinimumHeight() + "," + drawable.getMinimumWidth());
} else {
Log.w(this.getClass().getSimpleName(), "could not get thumbnail");
}
return drawable;
} catch (MalformedURLException e) {
Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
return null;
} catch (IOException e) {
Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
return null;
}
}
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
if (drawableMap.containsKey(urlString)) {
imageView.setImageDrawable(drawableMap.get(urlString));
}
final Handler handler = new Handler() {
@Override
public void handleMessage(Message message) {
imageView.setImageDrawable((Drawable) message.obj);
}
};
Thread thread = new Thread() {
@Override
public void run() {
//TODO : set imageView to a "pending" image
Drawable drawable = fetchDrawable(urlString);
Message message = handler.obtainMessage(1, drawable);
handler.sendMessage(message);
}
};
thread.start();
}
private InputStream fetch(String urlString) throws MalformedURLException, IOException {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(urlString);
HttpResponse response = httpClient.execute(request);
return response.getEntity().getContent();
}
}
希望对你有帮助。
【讨论】:
https://github.com/thest1/LazyList
在 Android 中显示图像的简单库。图像在后台异步下载。图像被缓存在 SD 卡和内存中。也可用于 GridView 并仅将图像显示到 ImageView 中。
请记住,这将在 SD 卡上创建一个名为 LazyList 的文件夹,但由于它是开源的,因此您可以轻松更改名称。这是在考虑列表的情况下构建的,但是您可以在任何地方轻松使用它。
【讨论】: