我在我的應用程序中動態創建了imageview。我試圖從URL加載圖像。但它不起作用。我已經嘗試了很多方法,並且我目前使用的代碼是如何從android中的URL將圖像加載到動態創建的imageview中?
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png").getContent());
img.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
但是圖像未加載。什麼是錯誤?
使用像Glide或Picasso或通用圖像加載器的圖像庫來加載圖像。它好得多 –