我用下面的代码从网上下载了一组图像:for(int i = 1; i < 12; i++) {
try {
URL imageURL = new URL("http://domain/drawimage.php?type=" + i + "&d1=" + this.d1 + "&d2=" + this.d2);
Bitmap image = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
bitmaps.add(image);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}然后当我想把图像插入LinearLayout (ll),图像就不会出现,尽管bitmaps.size() = 11。for(int i = 0; i < bitmaps.size(); i++) {
ImageView iv = new ImageView(c); // c = getApplicationContext()
iv.setImageBitmap(bitmaps.get(i));
iv.setVisibility(ImageView.VISIBLE);
ll.addView(iv);
}如果我使用TextView,就能运行。for(int i = 0; i < bitmaps.size(); i++) {
TextView tv = new TextView(c); // c = getApplicationContext()
tv.setText("image ");
tv.setGravity(Gravity.CENTER_HORIZONTAL);
ll.addView(tv);
}是加载的问题还是insertation失败?如何修复?
添加回答
举报
0/150
提交
取消