public class MainActivity extends Activity { private int[] imagearr = { R.drawable.bg01, R.drawable.bg02, R.drawable.bg03, R.drawable.bg04, R.drawable.bg05, }; private int count = 0; private ImageView imageview; Handler handler = new Handler() { public void handleMessage(android.os.Message msg) { if (msg.what == 0) { imageview.setImageResource(imagearr[count++]); if (count >= imagearr.length) { count = 0; } } }; }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageview = (ImageView) this.findViewById(R.id.imageview); new Thread(new Runnable() { @Override public void run() { while (true) { handler.sendEmptyMessage(0); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); //定时器也可以实现 // new Timer().schedule(new TimerTask() { // // @Override // public void run() { // handler.sendEmptyMessage(0); // } // }, 0, 2000); }}