- package com.luck.imageshow;
- import android.os.Bundle;
- import android.app.Activity;
- import android.view.Menu;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- public class ImageShow extends Activity {
- int []img=new int[]{
- R.drawable.im1,
- R.drawable.im2,
- R.drawable.im3,
- R.drawable.im4
- };
- int curr=0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_image_show);
- LinearLayout main= (LinearLayout)this.findViewById(R.id.root);
- final ImageView image=new ImageView(this);
- main.addView(image);
- image.setImageResource(img[0]);
- image.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- if(curr>=3){
- curr=-1;
- }
- image.setImageResource(img[++curr]);
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.image_show, menu);
- return true;
- }
- }
- 布局文件:
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:id="@+id/root"
- android:orientation="vertical"
- ></LinearLayout>
复制代码
|
|