布局

<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

更多相关文章

  1. 开机自启动3
  2. android 设置透明效果
  3. Android(安卓)待机时间
  4. 编译osg for android
  5. Android(安卓)Handler机制10之Native的实现
  6. android系统自带的主题与样式(theme and style)
  7. 局域网内搭建Android(安卓)SDK更新源
  8. 多点触控测试代码 PointerLocation
  9. Android(安卓)studio attribute android:fillColor报错

随机推荐

  1. Android拍照和图片处理类应用盘点
  2. 最简洁最好用的Android记事软件 - [ 迷你
  3. 雷锋读图:两百款Android手机上的淘宝
  4. Android(安卓)button自定义显示
  5. 介绍使用Cordova和Web Starter Kit开发An
  6. 你后悔做Android了吗?
  7. 反思|Android 列表分页组件Paging的设计
  8. android/IOS常用图片上传的两种方式
  9. 浅谈如何避免Android内存溢出
  10. Android拼图滑块验证码控件