Layout
<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>
Background code
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 classMainActivity3 extends Actionbaractivity {PrivateImageView imageview=NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.LAYOUT.ACTIVITY_MAIN_ACTIVITY3); ImageView=(ImageView) Findviewbyid (R.id.imageview); NewThread (NewRunnable () {@Override Public voidRun () {final Bitmap Bitmap=getpicture ("http://h.hiphotos.baidu.com/news/q%3D100/sign=be8e90f30cfa513d57aa68de0d6d554c/ C75c10385343fbf29d10a30cb47eca8065388fe4.jpg"); Try{Thread.Sleep ( -); } Catch(interruptedexception e) {e.printstacktrace (); } imageview.post (NewRunnable () {@Override Public voidrun () {imageview.setimagebitmap (bitmap); } }); }}). Start (); } PublicBitmap getpicture (String path) {Bitmap BM=NULL; Try{URL URL=NewURL (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 (); } returnBM; }}
For more information please see Android series experience: http://jingyan.baidu.com/article/48b558e3372fae7f38c09a1d.html
android--Perhaps the network picture