我在尋找的改性Imageviewclass其下載一個圖像並顯示它。 這也應該是可以顯示「下載失敗」 - 圖像和「負荷」 - 圖像。 如果有人知道這樣的班級,請讓我知道。ImageView的與圖像從地址
Thx!
我在尋找的改性Imageviewclass其下載一個圖像並顯示它。 這也應該是可以顯示「下載失敗」 - 圖像和「負荷」 - 圖像。 如果有人知道這樣的班級,請讓我知道。ImageView的與圖像從地址
Thx!
你可以用這個例子,只是通過活動實例在構造和擴展視圖類而不是Activity類。
好,謝謝,但不正是我#我想找......因爲我希望有一個「下載失敗」 - 圖像和「負荷」 - 圖像了。 –
希望這有助於U:
ImageView i = new ImageView(this);
i.setImageResource(" ur load image") // show any load image here..eg. gallery image
try {
/* Open a new URL and get the InputStream to load data from it. */
URL aURL = new URL("ur Image URL");
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
/* Buffered is always good for a performance plus. */
BufferedInputStream bis = new BufferedInputStream(is);
/* Decode url-data to a bitmap. */
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
/* Apply the Bitmap to the ImageView that will be returned. */
i.setImageBitmap(bm);
} catch (IOException e) {
i.setImageResource(R.drawable.error); // Error image here
Log.e("DEBUGTAG", "Remote Image Exception", e);
}
如果下載失敗?導致沒有連接或什麼? –
看看catch塊..還有就是IO異常處理網絡故障 –
啊是啊!謝謝,我會嘗試。 –
我還沒有看到這樣的組件,但它是一個好主意。 –
這是一個好主意,但你必須自己寫。不應該太難以分類當前的圖像視圖並添加功能。 – Spidy
好的,謝謝你們。 –