Android顯示網(wǎng)絡(luò)圖片實(shí)例
本文實(shí)例講述了Android顯示網(wǎng)絡(luò)圖片的方法,分享給大家供大家參考。具體方法如下:
一般來(lái)說(shuō),在Android中顯示一張網(wǎng)絡(luò)圖片其實(shí)是非常簡(jiǎn)單的,下面就是一個(gè)非常簡(jiǎn)單的例子:
步驟1:
① 創(chuàng)建你的Activity,本例中以ViewWebImageActivity說(shuō)明;
② 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)存溢出問(wèn)題解決方法
- 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之聯(lián)系人PinnedHeaderListView使用介紹
Android聯(lián)系人中的ListView是做得比較獨(dú)特的,這幾天,我把他提取出來(lái)了,寫成一個(gè)簡(jiǎn)單的例子,留著備用,感興趣的朋友可以參考下哈2013-06-06
Android SharedPreferences四種操作模式使用詳解
這篇文章主要介紹了Android SharedPreferences四種操作模式使用詳解的相關(guān)資料,這里介紹了獲取Android SharedPreferences的兩種方法及比較,和操作模式的介紹,需要的朋友可以參考下2017-07-07
Android實(shí)現(xiàn)強(qiáng)制下線功能的示例代碼
這篇文章主要介紹了Android實(shí)現(xiàn)強(qiáng)制下線功能的示例代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07
Android Kotlin環(huán)境使用ButterKnife的方法
本篇文章主要介紹了Android Kotlin環(huán)境使用ButterKnife的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
flutter 微信聊天輸入框功能實(shí)現(xiàn)
這篇文章主要介紹了flutter 微信聊天輸入框功能實(shí)現(xiàn),本文通過(guò)實(shí)例圖文相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-03-03
完美解決EditText和ScrollView的滾動(dòng)沖突(下)
這篇文章再次為大家詳細(xì)介紹了完美解決EditText和ScrollView滾動(dòng)沖突的方法,感興趣的小伙伴們可以參考一下2016-06-06
詳解Android系統(tǒng)中跨應(yīng)用數(shù)據(jù)分享功能的實(shí)現(xiàn)
這篇文章主要介紹了Android系統(tǒng)中跨應(yīng)用數(shù)據(jù)分享功能的實(shí)現(xiàn),文中分為發(fā)送文字、二進(jìn)制內(nèi)容和圖片三種情況來(lái)講,需要的朋友可以參考下2016-04-04

