我正在尋找類似於Android的SDWebImage的東西。什麼SDWebImage在iOS中是這樣做的:在Android版iOS中與SDWebImage類似嗎?
從URL加載圖像,使用緩存,做異步下載。
我在尋找類似的Android的東西。任何提示?
謝謝。
我正在尋找類似於Android的SDWebImage的東西。什麼SDWebImage在iOS中是這樣做的:在Android版iOS中與SDWebImage類似嗎?
從URL加載圖像,使用緩存,做異步下載。
我在尋找類似的Android的東西。任何提示?
謝謝。
我得到這個答案在下面的鏈接:Lazy load of images in ListView
package com.wilson.android.library;
/* 下一個 或更多貢獻者許可協議,授權給Apache軟件基金會(ASF)。請參閱本作品發行的NOTICE文件 以瞭解有關版權所有權的其他信息 。根據Apache許可證2.0版( 「許可證」),ASF向您授予此文件 ;除許可證符合 外,您不得使用此文件。你可以在
http://www.apache.org/licenses/LICENSE-2.0
獲得許可證的副本除非適用法律要求或書面同意, 軟件許可證下發布的上 按「原樣」的基礎,沒有擔保或條件任何 KIND,明示或暗示。根據許可證,請參閱許可證以獲取關於許可和限制 的 特定語言。
*/
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();
}
}
希望它能幫助。
在Applidium,我們最近將SDWebImage移植到Android。這叫做Shutterbug,它可以滿足你所要求的一切。
以下是該項目的鏈接:https://github.com/applidium/Shutterbug。請享用!
https://github.com/thest1/LazyList
一個簡單的庫中的Android顯示圖像。正在後臺異步下載圖像。圖像被緩存在SD卡和內存中。也可以用於GridView,只是將圖像顯示到ImageView中。
需要記住的是,這將在名爲LazyList的SD卡上創建一個文件夾,但由於它是開源的,您可以輕鬆更改名稱。這是建立在列表的頭腦中,但是您可以在任何地方輕鬆使用它。
類似的東西: http://stackoverflow.com/questions/2912054/lazy-load-images-on-listview-in-androidbeginner-level – ahsan