为什么我的 imageview 没有在 for 循环中更新,只有最后一个 url 中的图像显示在 imageview 中,而不是所有图像,我做错了什么?
public class LoadImageActivity extends Activity {
ImageView image_view;
Bitmap bitmap;
String[] imageLocation={
"http://wallbase1.org/thumbs/rozne/thumb-499842.jpg",
"http://ns3002439.ovh.net/thumbs/rozne/thumb-2493796.jpg",
"http://ns3002439.ovh.net/thumbs/rozne/thumb-2486664.jpg" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image_view = (ImageView)findViewById(R.id.imageview);
for (int i = 0; i < 2; i++) {
bitmap = loadImage(imageLocation[i]);
image_view.setImageBitmap(bitmap);
Animation rotate = AnimationUtils.loadAnimation(LoadImageActivity.this, R.anim.rotate);
findViewById(R.id.imageview).startAnimation(rotate);
}
}
public Bitmap loadImage(String image_location){
URL imageURL = null;
try {
imageURL = new URL(image_location);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection connection = HttpURLConnection)imageURL.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream inputStream = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);//Convert to bitmap
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
}