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