1、
int what = 0;
Thread thread = new Thread(new Runnable() {
public void run() {
while (true) {
handler.sendEmptyMessage((what++) % 4);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
2、
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
imageView.setImageResource(R.drawable.p1);
break;
case 1:
imageView.setImageResource(R.drawable.p2);
break;
case 2:
imageView.setImageResource(R.drawable.p3);
break;
case 3:
imageView.setImageResource(R.drawable.p4);
break;
}
super.handleMessage(msg);
}
};
3、thread.start();
注:
private int imageIds[];
//图片ID imageIds = new int[]{ R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e };
imgView.setImageDrawable(sdk.getContext().getResources().getDrawable(array[i]));