Android study NOTE 4: Image Display imageVIew

Source: Internet
Author: User

In the Multimedia Age, how can I avoid image display? Fortunately, android provides us with the image display control imageVIew. The following program will use this control to replace the displayed image with a touch screen.

Program starts running

 
 

Click the screen and change the image

 

Package snoopy. android;
 
Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. ImageView;
Import android. widget. LinearLayout;
 
 
Public class MixView extends Activity
{
// Define an array of access images. These images are saved in the drawable-mdpi folder. I used five Yanzi photos here, and Zizi fans are everywhere ~~~~~~~
Int [] images = new int [] {
R. drawable. sunyz_1,
R. drawable. sunyz_2,
R. drawable. sunyz_3,
R. drawable. sunyz_4,
R. drawable. sunyz_5,
};
Int currentImg = 0;
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
// Obtain the LinearLayout layout container
LinearLayout main = (LinearLayout) findViewById (R. id. root );
// The program creates the ImageView component.
Final ImageView image = new ImageView (this );
// Add the ImageView component to the LinearLayout layout container.
Main. addView (image );
// Display the first image www.2cto.com during initialization
Image. setImageResource (images [0]);
Image. setOnClickListener (new OnClickListener ()
{
@ Override
Public void onClick (View v)
{
If (currentImg> = 4)
{
CurrentImg =-1;
}
// Change the image displayed in the ImageView
Image. setImageResource (images [++ currentImg]);
}
});
}
}

From the column hn307165411


 

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.