Use the SimpleOnPageChangeListener()监听ViewPager事件, 在其中的onPageScrollStateChanged() method to determine whether it is a user sliding based on the parameters passed in. The code is roughly as follows
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
@Override
public void onPageScrollStateChanged(int state) {
if (state == ViewPager.SCROLL_STATE_DRAGGING) {
// 用户拖动ViewPager, 取消自动滑动
} else if (state == ViewPager.SCROLL_STATE_IDLE) {
// 滑动结束, 视情况是否重启自动滑动
}
}
});
Use the
SimpleOnPageChangeListener()
监听ViewPager事件, 在其中的onPageScrollStateChanged()
method to determine whether it is a user sliding based on the parameters passed in. The code is roughly as followsRewrite
onTouchEvent
事件,做个判断,ACTION_DOWN
就像这样handler.removeCallbacks(marqueeRunnable);
手动停止自动滚动,ACTION_UP
就像这样handler.postDelayed(marqueeRunnable, scrollDelayTime);
Enable auto-scroll manually.