话不多说,直接上码:xml文件,简单的线性布局
<?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="下一张"
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>
效果图
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{
//定义一个访问照片的数组
int[] images=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.imageview);
final ImageView image1=(ImageView)findViewById(R.id.image1);
final Button next=(Button)findViewById(R.id.button3);
//定义查看下一张图片的监听器
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//控制Image View显示下一张照片
image1.setImageResource(
images[++currentImg % images.length]
);
}
});
}}
原文地址:http://nomeatnofat.blog.51cto.com/10289035/1659222