Implement button control ImageView show next photo

Source: Internet
Author: User

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

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.