Android——获取网络图片
2015-02-11 13:02
288 查看
布局
后台代码
更多介绍请看android系列经验: http://jingyan.baidu.com/article/48b558e3372fae7f38c09a1d.html
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.basillee.asus.demo.MainActivity3"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" ></ImageView> </RelativeLayout>
后台代码
package com.basillee.asus.demo; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.ImageView; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class MainActivity3 extends ActionBarActivity { private ImageView imageView=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_activity3); imageView= (ImageView) findViewById(R.id.imageView); new Thread(new Runnable() { @Override public void run() { final Bitmap bitmap=getPicture("http://h.hiphotos.baidu.com/news/q%3D100/sign=be8e90f30cfa513d57aa68de0d6d554c/c75c10385343fbf29d10a30cb47eca8065388fe4.jpg"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } imageView.post(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmap); } }); } }).start(); } public Bitmap getPicture(String path){ Bitmap bm=null; try{ URL url=new URL(path); URLConnection connection=url.openConnection(); connection.connect(); InputStream inputStream=connection.getInputStream(); bm= BitmapFactory.decodeStream(inputStream); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return bm; } }
更多介绍请看android系列经验: http://jingyan.baidu.com/article/48b558e3372fae7f38c09a1d.html
相关文章推荐
- Android中获取网络图片的方法(如果手机缓存里面有就从缓存获取)
- Android从网络获取图片并放大
- android学习笔记16--------------Android实现网络图片与html源码获取
- android - 获取网络图片
- 【android基础】之Android获取网络上的图片结合ImageView的简单应用
- Android开发技术之──获取网络图片
- Android 获取网络图片方法
- Android中获取网络图片的方法(如果手机缓存里面有就从缓存获取)
- Android成长之路-获取网络数据(图片)
- Android中关于ImageView网络获取的图片的缩放问题
- Android 如何获取网络上的图片
- Android--从网络获取图片
- android HttpURLConnection编程详解,获取网络图片,html代码查看
- Android进阶2之Https访问网络资源(获取网络图片)
- android获取互联网图片与源代码——网络编
- Android获取网络图片的方法
- android HttpURLConnection编程详解,获取网络图片,html代码查
- android 网络获取图片并存储
- android 简单实现获取网络图片
- Android进阶2之Https访问网络资源(获取网络图片)