我有 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;
}
有没有最简单的方法(更少的时间消耗)来执行相同的任务?