I ran into the same problem. The following is my conclusion:
When the page is actually resized, it is called PageSelected. But it is called before the animation.
When the animation is stopped, onPageScrollStateChanged will be called with the SCROLL_STATE_IDLE state.
So, you need to combine these two function calls to call your function.
Good luck.
private class PageChangeListener implements OnPageChangeListener {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
isPageChanged = true;
}
@Override
public void onPageScrollStateChanged(int state) {
switch (state) {
case ViewPager.SCROLL_STATE_IDLE:
if (isPageChanged) {
updateCurrentPage();
isPageChanged = false;
}
break;
case ViewPager.SCROLL_STATE_DRAGGING:
break;
case ViewPager.SCROLL_STATE_SETTLING:
break;
}
}
}
source
share