ImageView usage (android)

Source: Internet
Author: User

Image view is used to display images in android. The code here is from the example in the book. It is easy to use. Now I think android development is really convenient.

The Code is as follows:

Xml

<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">

<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"/>
<ImageView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: id = "@ + id/image1"
/>

</LinearLayout>

 

Java code

Package zziss. android. imagetest;

Import android. app. Activity;
Import android. OS. Bundle;
Import android. OS. Handler;
Import android. OS. Message;
Import android. widget. ImageView;

Public class ImageTestActivity extends Activity {
/** Called when the activity is first created .*/
Private ImageView iv;
Private int img_alpha = 0;
Handler iHandler = new Handler ();
Private boolean iIsRun = false;

@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Iv = (ImageView) this. findViewById (R. id. image1 );
Iv. setImageResource (R. drawable. q2 );
Iv. setAlpha (img_alpha );
IIsRun = true;

New Thread (new Runnable ()
{

@ Override
Public void run (){
// TODO Auto-generated method stub
While (iIsRun)
{
Try
{
Thread. sleep (200 );
UpdateAlpha ();
}
Catch (InterruptedException e)
{
E. printStackTrace ();
}
}
}

} // End new runnable
). Start (); // end new thread

IHandler = new Handler ()
{

@ Override
Public void handleMessage (Message msg ){
// TODO Auto-generated method stub
Super. handleMessage (msg );
Iv. setAlpha (img_alpha );
Iv. invalidate ();
}


};

}

Private void updateAlpha ()
{
If (img_alpha + 7 <= 255)
{
Img_alpha + = 7;
} Else
{
Img_alpha = 255;
IIsRun = false;
}
IHandler. sendMessage (iHandler. obtainMessage ());
}
}

 

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.