类似于iOS for Android中的SDWebImage?

时间:2011-09-07 23:22:12

标签: android ios

我正在寻找类似于SDWebImage for Android的东西。 SDWebImage在iOS中的作用是:

从URL加载图片,使用缓存,进行异步下载。

我正在为Android寻找类似的东西。任何提示?

感谢。

4 个答案:

答案 0 :(得分:8)

我正在使用的一个简单的项目称为Picasso:

https://github.com/square/picasso

我在项目的iOS端使用SDWebImage,Picasso也很简单。

答案 1 :(得分:3)

在Applidium,我们最近将SDWebImage移植到Android。它被称为Shutterbug,它可以满足您的所有要求。

以下是该项目的链接:https://github.com/applidium/Shutterbug。享受!

答案 2 :(得分:1)

我在以下链接中得到了这个答案:Lazy load of images in ListView

   package com.wilson.android.library;

/ *  获得Apache软件基金会(ASF)的许可 或更多贡献者许可协议。请参阅NOTICE文件 与此工作分发以获取更多信息 关于版权所有权。 ASF许可此文件 根据Apache许可证2.0版( “执照”);除非符合规定,否则您不得使用此文件 与许可证。您可以在

获取许可证副本

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();
}

}

希望它有所帮助。

答案 3 :(得分:0)

https://github.com/thest1/LazyList

一个在Android中显示图像的简单库。图像正在后台异步下载。图像正在缓存在SD卡和内存中。也可以用于GridView,只是将图像显示到ImageView中。

需要注意的是,这将在SD卡上创建一个名为LazyList的文件夹,但由于它是开源的,因此您可以轻松更改名称。这是建立在列表的基础上,但你可以在任何地方轻松使用它。