Android顯示網(wǎng)絡(luò)圖片實(shí)例
本文實(shí)例講述了Android顯示網(wǎng)絡(luò)圖片的方法,分享給大家供大家參考。具體方法如下:
一般來說,在Android中顯示一張網(wǎng)絡(luò)圖片其實(shí)是非常簡(jiǎn)單的,下面就是一個(gè)非常簡(jiǎn)單的例子:
步驟1:
① 創(chuàng)建你的Activity,本例中以ViewWebImageActivity說明;
② ViewWebImageActivity中的代碼如下:
Bitmap bmImg;
ImageView imView;
Button button1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imView = (ImageView) findViewById(R.id.imview);
imView.setImageBitmap(returnBitMap(imageUrl));
}
public Bitmap returnBitMap(String url) {
URL myFileUrl = null;
Bitmap bitmap = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
③ 其中,returnBitMap(String url) 方法就是具體實(shí)現(xiàn)網(wǎng)絡(luò)圖片轉(zhuǎn)換成bitmap。
步驟2:
修改你的main.xml文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
< /LinearLayout>
步驟3:
在你的AndroidManifest.xml文件的節(jié)點(diǎn)上面添加,這是由于Android有很多的權(quán)限限制,否則圖片是不能在你的模擬器上顯示的。
希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
- Android 網(wǎng)絡(luò)圖片查看顯示的實(shí)現(xiàn)方法
- Android讀取本地或網(wǎng)絡(luò)圖片并轉(zhuǎn)換為Bitmap
- Android 異步獲取網(wǎng)絡(luò)圖片并處理導(dǎo)致內(nèi)存溢出問題解決方法
- Android 下載網(wǎng)絡(luò)圖片并顯示到本地
- 簡(jiǎn)單實(shí)現(xiàn)Android讀取網(wǎng)絡(luò)圖片到本地
- Android使用線程獲取網(wǎng)絡(luò)圖片的方法
- 在Android的應(yīng)用中實(shí)現(xiàn)網(wǎng)絡(luò)圖片異步加載的方法
- Android實(shí)現(xiàn)網(wǎng)絡(luò)圖片瀏覽功能
- Android 讀取sdcard上的圖片實(shí)例(必看)
- Android sdcard實(shí)現(xiàn)圖片存儲(chǔ) 、聯(lián)網(wǎng)下載
- Android開發(fā)實(shí)現(xiàn)加載網(wǎng)絡(luò)圖片并下載至本地SdCard的方法
相關(guān)文章
Android實(shí)現(xiàn)給TableLayou繪制邊框的方法
這篇文章主要介紹了Android實(shí)現(xiàn)給TableLayou繪制邊框的方法,涉及Android TableLayou布局控制相關(guān)技巧,需要的朋友可以參考下2016-03-03Android自定義View實(shí)現(xiàn)地鐵顯示牌效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)地鐵顯示牌效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11Android開發(fā)自學(xué)筆記(三):APP布局上
這篇文章主要介紹了Android開發(fā)自學(xué)筆記(三):APP布局上,本文講解了添加ViewGroup、添加ViewGroup、定義string內(nèi)容、添加Button、運(yùn)行程序查看效果等內(nèi)容,需要的朋友可以參考下2015-04-04Android ScrollView滑動(dòng)實(shí)現(xiàn)仿QQ空間標(biāo)題欄漸變
這篇文章主要為大家詳細(xì)介紹了Android ScrollView滑動(dòng)實(shí)現(xiàn)仿QQ空間標(biāo)題欄漸變,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08Android學(xué)習(xí)筆記之ListView復(fù)用機(jī)制詳解
本篇文章主要介紹了Android學(xué)習(xí)筆記之ListView復(fù)用機(jī)制詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02Android ListView長(zhǎng)按彈出菜單二種實(shí)現(xiàn)方式示例
這篇文章主要介紹了Android ListView長(zhǎng)按彈出菜單的方法,大家參考實(shí)現(xiàn)2013-11-11Android編程實(shí)現(xiàn)Listview點(diǎn)擊展開和隱藏的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)Listview點(diǎn)擊展開和隱藏的方法,涉及Android中Listview的響應(yīng)點(diǎn)擊與樣式變換相關(guān)操作技巧,需要的朋友可以參考下2015-12-12Android開發(fā)之串口編程原理和實(shí)現(xiàn)方式
提到串口編程,就不得不提到JNI,不得不提到JavaAPI中的文件描述符類:FileDescriptor;下面我分別對(duì)JNI、FileDescriptor以及串口的一些知識(shí)點(diǎn)和實(shí)現(xiàn)的源碼進(jìn)行分析說明,感興趣的朋友可以了解下2013-01-01