Android Footstep---picture view

Source: Internet
Author: User

Simple picture Browser, realize the image display and click to switch the next one

First, a simple linear layout container is defined inside the main.xml.

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "        android:id=" @+id/root "        android:orientation=" vertical "        android: Layout_width= "Wrap_content"        android:layout_height= "Wrap_content"       >    </ Linearlayout>


And then inside the Mianactivity.java.

 PackageOrg.crazyit.helloworld;ImportAndroid.os.Bundle;Importandroid.app.Activity;Importandroid.view.DragEvent;ImportAndroid.view.Menu;ImportAndroid.view.View;ImportAndroid.view.View.OnDragListener;ImportAndroid.widget.Button;ImportAndroid.widget.ImageView;Importandroid.widget.LinearLayout;ImportAndroid.widget.TextView; Public classMainactivityextendsActivity {//defines an array to access a picture    int[] Images =New int[]{R.drawable.ic_launcher, R.drawable.aaa, R.DRAWABLE.ASD, r.drawable.sss    }; intcurrentimg = 0; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //get a linear layout containerLinearLayout main =(LinearLayout) Findviewbyid (r.id.root); //Program Create Iamgeview component        FinalImageView image =NewImageView ( This); //add into LayoutMain.addview (image); //Initialize to display the first pictureImage.setimageresource (images[0]); Image.setonclicklistener (NewView.onclicklistener () { Public voidOnClick (View v) {if(Currentimg >=4) {currentimg=-1; } image.setimageresource (images[++currentimg]);    }                    }); }}

R.drawable.ic_launcher,
R.DRAWABLE.AAA,
R.DRAWABLE.ASD,
R.drawable.sss

It's a resource picture on res/drawable.

Defines an array, an INT images holds the image ID,

Currentimg is the subscript of the image array, and through its + +, it realizes the image reading +1.

Android Footstep---picture view

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.