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