1

我有 20 个不同图像的 URL。我需要从 URL 下载 20 张图像并将其显示在网格视图中。对我来说,下载图像内容需要很多时间。以下是我在 Image Adapter 类中使用的代码。

    public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(220, 200));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(1, 1, 1,0);
    } else {
        imageView = (ImageView) convertView;
    }
    imageView.setImageDrawable(GetDrawableImage(url));
    return imageView;
}
private Drawable GetDrawableImage(String zurlP)
{   InputStream InputStreamL = null;
    Drawable DrawableImageL = null;  
try {
        InputStreamL = (InputStream) new URL(zurlP).getContent();
        DrawableImageL = Drawable.createFromStream(InputStreamL, "src");
    } catch (MalformedURLException e) {          
    } catch (IOException e) {           
    }  
    return DrawableImageL;
}  

有没有最简单的方法(更少的时间消耗)来执行相同的任务?

4

2 回答 2

3

是的..,您可以使用 Asynctask 或 Painless 线程从服务器加载大图像。下载后缓存图像。您可以为此使用 [Fedor lazylist] (https://github.com/thest1/LazyList)

各种可能性。

多线程

缓存

无痛穿线

大型位图加载

或者你可以简单地用拇指指甲。表示从服务器获取缩略图而不是位图。加载将生效

于 2012-11-16T07:34:14.113 回答
2

您需要在其他线程中下载图像。您可以使用图像加载器

于 2012-11-16T07:36:43.750 回答