1

我的应用程序中有一个自定义列表视图,它显示图像和文本。我从 URL 获得的图像,使用下面的代码:

private static Drawable ImageOperations(Context ctx, String url,
        String saveFilename) {
    try {
        InputStream is = (InputStream) fetch(url);
        Drawable d = Drawable.createFromStream(is, "src");
        return d;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

public static Object fetch(String address) throws MalformedURLException,
IOException {
    URL url = new URL(address);
    Object content = url.getContent();
    return content;
}

一切都很完美,除了列表视图滚动,它非常慢。如果我禁用图像,滚动速度 smooth-ens ,但启用图像时,它会滞后很多。

有什么可能的方法可以减少或消除这种滞后?

谢谢

4

3 回答 3

3

您需要在后台进行抓取。您可以使用的示例之一: http ://android-developers.blogspot.com/2010/07/multithreading-for-performance.html

于 2010-10-12T14:03:31.767 回答
2

use this library for downloading images in background and caching.. it won't hurt the UI https://github.com/koush/UrlImageViewHelper

于 2011-04-20T22:02:56.587 回答
1

您是否懒惰地加载图像? 有关详细信息,请参阅此问题

于 2010-10-12T14:03:41.957 回答