android通过图片网址获得图片并显示在imageView中。
下面就简单的来说明操作过程:
首先必须在布局文件中声明imageView控件:
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
还必须在清单文件中加入访问网络的权限:
<uses-permission android:name="android.permission.INTERNET" />
其次:用一个service类来实现访问http协议,并且获得链接的返回值这个过程:htmlPath是图片的网络地址
public class PageService {
/**@description:获取图片的数据
* @author:Administrator
* @return:byte[]
* @param htmlpath
* @return
* @throws Exception
*/
public static byte[] getImage(String htmlpath) throws Exception {
byte[] imagearray = null;
URL url = new URL(htmlpath);
HttpURLConnection conn = (HttpURLConnection) url.openConn