Android study NOTE 4: Image Display imageview

Source: Internet
Author: User

In the Multimedia Age, how can I avoid image display? Fortunately, Android provides the Image Display Control imageview.ProgramYou can use this control to change the image displayed on the 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 {// defines an array of access images. These images are saved in the drawable-mdpi folder. I used five Yanzi photos here, pose 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; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // obtain the linearlayout layout container linearlayout main = (linearlayout) findviewbyid (R. id. root); // create the imageview component final imageview image = new imageview (this); // Add the imageview component to the linearlayout layout container main. addview (image); // the first image is displayed at initialization. setimageresource (images [0]); image. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {If (currentimg> = 4) {currentimg =-1;} // change the image displayed in the imageview. setimageresource (images [++ currentimg]) ;}}

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.