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