android--Perhaps the network picture

Source: Internet
Author: User


<relativelayout xmlns:android=""Xmlns:tools="Http://"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;import;import Android.os.bundle;import;import Android.widget.imageview;import;import;import;import;import; Public classMainActivity3 extends Actionbaractivity {PrivateImageView imageview=NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.LAYOUT.ACTIVITY_MAIN_ACTIVITY3); ImageView=(ImageView) Findviewbyid (; NewThread (NewRunnable () {@Override Public voidRun () {final Bitmap Bitmap=getpicture (" C75c10385343fbf29d10a30cb47eca8065388fe4.jpg"); Try{Thread.Sleep ( -); } Catch(interruptedexception e) {e.printstacktrace (); } (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:

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: 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.