新聞中心
Android手機操作系統(tǒng)已經(jīng)出現(xiàn)就受到了用戶的好評。各大手機廠商也開始利用這一開源的系統(tǒng)抓住商機,發(fā)展自己的產(chǎn)業(yè)。在這里先來了解一下這一操作系統(tǒng)的一個小技巧,有關(guān)Android顯示網(wǎng)絡(luò)圖片的實現(xiàn)。#t#

公司主營業(yè)務(wù):成都網(wǎng)站制作、做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)公司是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)公司推出望花免費做網(wǎng)站回饋大家。
在Android中顯示一張網(wǎng)絡(luò)圖片其實是超級簡單的,下面就一個非常簡單的例子:
Android顯示網(wǎng)絡(luò)圖片Step1:
1、創(chuàng)建你的Activity,本例中以ViewWebImageActivity說明;
2、ViewWebImageActivity中的代碼如下:
- String imageUrl = "http://hiphotos.baidu.com/baidu/pic
/item/7d8aebfebf3f9e125c6008d8.jpg";- //這就是你需要顯示的網(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;
- }
3、其中,returnBitMap(String url) 方法就是具體實現(xiàn)網(wǎng)絡(luò)圖片轉(zhuǎn)換成bitmap。
Android顯示網(wǎng)絡(luò)圖片Step2:
1、修改你的main.xml文件如下:
- < ?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>
Android顯示網(wǎng)絡(luò)圖片Step3:
在你的AndroidManifest.xml文件的< /manifest>節(jié)點上面添加< uses-permission android:name="android.permission.INTERNET" />,這是由于Android有很多的權(quán)限限制,否則圖片是不能在你的模擬器上顯示的。
網(wǎng)頁標(biāo)題:Android顯示網(wǎng)絡(luò)圖片相關(guān)實現(xiàn)方法淺談
鏈接分享:http://m.fisionsoft.com.cn/article/dpgicho.html


咨詢
建站咨詢
