首页 > 代码库 > Android -- 简单的图片浏览器

Android -- 简单的图片浏览器

1. 效果图

 

  点击图片进行切换   切换到下一张图片

2. 实现代码

public class MainActivity extends Activity {    int[] images = new int[] { R.drawable.pic, R.drawable.pic2,            R.drawable.pic3, R.drawable.pic4, R.drawable.pic5 };    int currentImg = 0;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                LinearLayout main =(LinearLayout) findViewById(R.id.root);        final ImageView image = new ImageView(this);        main.addView(image);                image.setImageResource(images[0]);        image.setOnClickListener(new OnClickListener() {                        @Override            public void onClick(View v) {                // TODO Auto-generated method stub                                image.setImageResource(images[++currentImg % images.length]);            }        });            }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.main, menu);        return true;    }}
MainActivity

 

Android -- 简单的图片浏览器