android--Perhaps the network picture

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.