你的位置:首页 > 操作系统

[操作系统]SlidePictures


 

package com.example.SlidePictures;import java.util.Timer;import java.util.TimerTask;import com.example.flashingpictures.R;import android.media.Image;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.app.Activity;import android.text.format.Time;import android.view.Menu;import android.widget.ImageView;public class MainActivity extends Activity {  private Image image;  //定义变化图片  int[] images={    R.drawable.a,    R.drawable.b,    R.drawable.c,    R.drawable.d,    R.drawable.e,  };  //定义传递信息  //0x开头表示16进制  int SING=0x11;  //照片顺序  int num=0;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);        final ImageView image=(ImageView)findViewById(R.id.imageView);    final Handler handler=new Handler(){      @Override      public void handleMessage(Message msg) {        // TODO Auto-generated method stub        super.handleMessage(msg);        if(msg.what==SING){          image.setImageResource(images[num++]);          if(num>=4){            num=0;          }        }              }        };    new Timer().schedule(new TimerTask() {            @Override      public void run() {        // TODO Auto-generated method stub        Message msg=new Message();        msg.what=SING;        handler.sendMessage(msg);      }    }, 0,2000);  }  @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;  }}

效果执行图: