Words not much to say, directly on the code: XML file, simple linear layout
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:orientation= "Vertical" >
<linearlayout
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:orientation= "Horizontal"
android:gravity= "Center" >
</LinearLayout>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:id= "@+id/button3"
Android:text= "Next One"
android:layout_gravity= "Right"/>
<imageview
Android:id= "@+id/image1"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:src= "@drawable/cat"
Android:scaletype= "Fitcenter"
/>
</LinearLayout>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/0E/wKioL1VytXzTTzDrAAEQNyEvK9g851.jpg "title=" QQ picture 20150606164655.png "alt=" Wkiol1vytxzttzdraaeqnyevk9g851.jpg "/>
Package com.example.administrator.myapplication;
Import android.app.Activity;
Import Android.content.DialogInterface;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.Window;
Import Android.widget.Button;
Import Android.widget.ImageView;
/**
* Created by Administrator on 2015/6/6.
*/
public class Textimageactivity extends activity{
Define an array of access photos
Int[] Images=new int[]{
R.drawable.cat,
R.drawable.dog,
R.drawable.happen,
R.drawable.hashiqi,
R.drawable.what,
R.drawable.name,
};
Define the photos that are displayed by default
int currentimg=2;
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Requestwindowfeature (window.feature_no_title);//Hide TITLE
Setcontentview (R.layout.imageview);
Final ImageView image1= (ImageView) Findviewbyid (r.id.image1);
Final button next= (button) Findviewbyid (R.id.button3);
Define a listener to view the next picture
Next.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
Control the image view to display the next picture
Image1.setimageresource (
Images[++currentimg% images.length]
);
}
});
}}
Implement button control ImageView show next photo