Android-imageview Picture View Demo

Source: Internet
Author: User

Code

 Packagecom.lxt008;ImportCOM.LXT008.R;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.os.Message;ImportAndroid.widget.ImageView;ImportAndroid.widget.TextView; Public classActivity01extendsactivity{//declaring ImageView ObjectsImageView ImageView;    TextView TextView; //the alpha value of the ImageView,    intImage_alpha = 255; Handler Mhandler=NewHandler (); //Control Thread    BooleanIsrung =false; /**Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.main); Isrung=true; //get the ImageView objectImageView = (ImageView) This. Findviewbyid (R.ID.IMAGEVIEW01); TextView= (TextView) This. Findviewbyid (R.ID.TEXTVIEW01); //set up a picture resource for ImageView. It can also be written in the XML layout as follows//android:src= "@drawable/logo"Imageview.setimageresource (R.drawable.logo); //set the alpha value of the ImageViewImageview.setalpha (Image_alpha); //open a thread to decrement the alpha value        NewThread (NewRunnable () { Public voidrun () { while(Isrung) {Try{Thread.Sleep (200); //Update alpha ValueUpdatealpha (); }                    Catch(interruptedexception e) {e.printstacktrace ();        }}}). Start (); //Update ImageView View after accepting messagesMhandler =NewHandler () {@Override Public voidhandlemessage (Message msg) {Super. Handlemessage (msg);                Imageview.setalpha (Image_alpha); Textview.settext ("Now the alpha value is:" +integer.tostring (Image_alpha)); //Updateimageview.invalidate ();    }        }; }         Public voidUpdatealpha () {if(image_alpha-7 >= 0) {Image_alpha-= 7; }        Else{Image_alpha= 0; Isrung=false; }        //send a message that needs to update the ImageView viewMhandler.sendmessage (Mhandler.obtainmessage ()); }}

Layout file

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"    ><ImageViewAndroid:id= "@+id/imageview01"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"    ></ImageView><TextViewAndroid:id= "@+id/textview01"Android:layout_below= "@id/imageview01"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"    ></TextView></LinearLayout>

Android-imageview Picture View demo

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.