用户滑动时停止轮播,松开时继续轮播
程序员文章站
2022-06-04 10:44:51
...
vpBanner.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
switch (state) {
case ViewPager.SCROLL_STATE_DRAGGING:
//用户正在滑动,暂停轮播
handler.sendEmptyMessage(BANNER_PAUSE);
break;
case ViewPager.SCROLL_STATE_IDLE:
//滑动结束,继续轮播
handler.sendEmptyMessageDelayed(BANNER_NEXT, 5000);
break;
}
}
});
推荐阅读