简体   繁体   中英

ListView scrolling lag in android

I am having a customized list view in my application, which is showing an image and text. The Image I am getting from URL, using the code below:

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

all is working perfect, except the list view scrolling, its very slow. If I disable the images, the scroll speed smooth-ens , but with the image enabled, it lags alot.

Is there any possible way I can reduce or remove this lagging?

Thanks

You need to do your fetching in the background. One of the examples you can use : http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html

使用此库在后台下载图像并进行缓存..不会伤害UI https://github.com/koush/UrlImageViewHelper

Are you lazy loading your images? See this question for details .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM