android学习2 简单图片浏览器

public class mixView extends Activity{

 

int[] images = new int[]{

R.drawable.ic_launcher,//图片名称

R.drawable.abc,

R.drawable.ic_launcher,

R.drawable.abc,};

int currentImg = 0;

@Override

protected void onCreate(Bundle savedInstanceState) {

 

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

//获取LinearLayout布局容器

LinearLayout main = (LinearLayout) findViewById(R.id.root);

//程序创建ImageView组建

final ImageView image = new ImageView(this);

//将ImageView组建添加到LinearLayout 布局容器中

main.addView(image);

image.setImageResource(images[0]);

image.setOnClickListener(new OnClickListener(){

 

@Override

public void onClick(View v) {

//改变ImageView里显示的图片

image.setImageResource(images[++currentImg%images.length]);

 

}

 

});

 

}

}

 来自:疯狂android

你可能感兴趣的:(android)