【问题标题】:ListView scrolling lag in androidandroid中的ListView滚动滞后
【发布时间】:2010-10-12 14:00:03
【问题描述】:

我的应用程序中有一个自定义列表视图,其中显示了图像和文本。 我从 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 ,但启用图像时,它会滞后很多。

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

谢谢

【问题讨论】:

    标签: android image listview scroll lag


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      使用这个库在后台下载图像和缓存.. 它不会伤害用户界面 https://github.com/koush/UrlImageViewHelper

      【讨论】:

        【解决方案3】:

        您是否懒惰地加载图像? See this question for details.

        【讨论】:

          猜你喜欢
          • 2021-07-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-05-17
          • 1970-01-01
          相关资源
          最近更新 更多