我有一个viewpager,其中有图像,我想自动滚动它们,我已经使用了一些代码,但是自动滚动不会显示最后一张图像
int currentPage = 0;
Timer timer;
final long DELAY_MS = 500; //delay in milliseconds before task is to
be
executed
final long PERIOD_MS = 3000;
viewPager = view.findViewById(R.id.viewPager);
NUM_PAGES = uploads1.size();
showDots();
ImageAdapter adapter = new ImageAdapter(getContext(), uploads1);
viewPager.setAdapter(adapter);
final Handler handler = new Handler();
final Runnable Update = new Runnable() {
public void run() {
if (currentPage == NUM_PAGES - 1) {
currentPage = 0;
}
viewPager.setCurrentItem(currentPage++, true);
}
};
timer = new Timer(); // This will create a new Thread
timer.schedule(new TimerTask() { // task to be scheduled
@Override
public void run() {
handler.post(Update);
}
}, DELAY_MS, PERIOD_MS);
有人可以帮忙吗?谢谢。