private int currentItem = 0;
#new一个Handler 和 Runnable
private final Handler myHandler = new Handler();
private final Runnable slideRunnable = new Runnable() {
@Override
public void run() {
currentItem++;
mGallery.setSelection(currentItem,false);
#模拟动画效果
mGallery.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT,null);
#设置下次滑动的定时器
myHandler.postDelayed(this, 4000);
}
};
#启动定时器
myHandler.postDelayed(slideRunnable, 4000);
注: 关闭此定时器方法
myHandler.removeCallbacks(slideRunnable);