android按钮实现下一页,实现Button控制ImageView显示下一张照片

话不多说,直接上码:xml文件,简单的线性布局

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:gravity="center">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/button3"

android:text="下一张"

android:layout_gravity="right" />

android:id="@+id/p_w_picpath1"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:src="@drawable/cat"

android:scaleType="fitCenter"

/>

效果图a7b916cbb2aed118c26481dcc03a85d9.png

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 Textp_w_picpathActivity extends Activity{

//定义一个访问照片的数组

int[] p_w_picpaths=new int[]{

R.drawable.cat,

R.drawable.dog,

R.drawable.happen,

R.drawable.hashiqi,

R.drawable.what,

R.drawable.name,

};

//定义默认显示的照片

int currentImg=2;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏TITLE

setContentView(R.layout.p_w_picpathview);

final ImageView p_w_picpath1=(ImageView)findViewById(R.id.p_w_picpath1);

final Button next=(Button)findViewById(R.id.button3);

//定义查看下一张图片的监听器

next.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

//控制Image View显示下一张照片

p_w_picpath1.setImageResource(

p_w_picpaths[++currentImg % p_w_picpaths.length]

);

}

});

}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值