我从这个网站http://androidopentutorials.com/android-image-slideshow-using-viewpager/获得了一个带有视图寻呼机的幻灯片 我想设置Motion事件,如果最后一个项目的位置,我滑动该项目和位置返回到第一个。如何实现呢?
...
mViewPager = (ViewPager) app.findViewById(R.id.view_pager);
mIndicator = (CirclePageIndicator) app.findViewById(R.id.indicator);
mIndicator.setOnPageChangeListener(new PageChangeListener());
mViewPager.setOnPageChangeListener(new PageChangeListener());
mViewPager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction()) {
case MotionEvent.ACTION_CANCEL:
Utils.log("ACTION_CANCEL " + products.size());
break;
case MotionEvent.ACTION_UP:
// calls when touch release on ViewPager
Utils.log("ACTION_UP " + products.size());
if (products != null && products.size() != 0) {
stopSliding = false;
runnable(products.size());
handler.postDelayed(animateViewPager,
ANIM_VIEWPAGER_DELAY_USER_VIEW);
}
break;
case MotionEvent.ACTION_MOVE:
// calls when ViewPager touch
Utils.log("ACTION_MOVE " + products.size());
if (handler != null && stopSliding == false) {
stopSliding = true;
handler.removeCallbacks(animateViewPager);
}
break;
}
return false;
}
});
...
谢谢