android讲义2之图片变换

//定义一个访问图片的数组
int[] images = new int[]{
R.drawable.java,
R.drawable.ee,
R.drawable.classic,
R.drawable.ajax,
R.drawable.xml,
};

//获取LinearLayout布局容器
LinearLayout main = (LinearLayout)findViewById(R.id.root);

//将ImageView组件添加到LinearLayout布局容器中
main.addView(image);

//初始化时显示第一张图片
image.setImageResource(images[0]);

//在imageView上点击变换照片

public void onClick(View v)
{
if (currentImg >= 4)
{
currentImg = -1;
}
//改变ImageView里显示的图片
image.setImageResource(images[++currentImg]);
}

原文地址:https://www.cnblogs.com/lee0oo0/p/2378254.html