欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android顯示網(wǎng)絡(luò)圖片實(shí)例

 更新時(shí)間:2014年10月13日 10:18:29   投稿:shichen2014  
這篇文章主要介紹了Android顯示網(wǎng)絡(luò)圖片的方法,以實(shí)例形式展示了Android程序顯示網(wǎng)絡(luò)圖片的方法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android顯示網(wǎng)絡(luò)圖片的方法,分享給大家供大家參考。具體方法如下:

一般來說,在Android中顯示一張網(wǎng)絡(luò)圖片其實(shí)是非常簡(jiǎn)單的,下面就是一個(gè)非常簡(jiǎn)單的例子:

步驟1:

① 創(chuàng)建你的Activity,本例中以ViewWebImageActivity說明;
② ViewWebImageActivity中的代碼如下:

復(fù)制代碼 代碼如下:
String imageUrl = "http://www.dbjr.com.cn/images/logo.gif"; //這就是你需要顯示的網(wǎng)絡(luò)圖片---網(wǎng)上隨便找的
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文件如下:

復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<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ì)有所幫助。

相關(guān)文章

最新評(píng)論