Using a linear layout, save the picture in an XML file, call the array store in Java backend Code, add a click event, and then iterate through each of the images in the array after clicking the picture;
The specific code is as follows:
XML code:
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical"
Android:id= "@+id/root"
>
</LinearLayout>
Java code:
Package Com.example.code;
import Android.os.Bundle;
import android.app.Activity;
import Android.view.Menu;
import Android.view.View;
import Android.widget.ImageView;
import android.widget.LinearLayout;
Public class Mainactivity extends Activity {
//define an array to access the picture
int[] Images=new int[]{
R.drawable.a,
R.drawable.android,
R.drawable.android_os,
R.drawable.android3png,
R.drawable.android4png,
};
int currentimg=0;
@Override
protected void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.main);
//Get LinearLayout Linear layout container
linearlayout main= (linearlayout) Findviewbyid (r.id.root);
//Create Imgview Components
final ImageView image=new ImageView (this);
//Add the Imgview component to the LinearLayout layout container
Main.addview (image);
//Show first picture when initializing
Image.setimageresource (images[0]);
//Add Click event
Image.setonclicklistener (New View.onclicklistener () {
@Override
Public void OnClick (View v) {
//TODO auto-generated method stub
//Change the picture shown in ImageView
Image.setimageresource (images[++currentimg% images.length]);
}
});
}
}
Android Development-Simple Picture browser