Android ViewPager动画 [英] Android viewpager animation
本文介绍了Android ViewPager动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在此函数调用后动画结束时得到通知:
I would like to be informed when the animation ends after this function call:
viewPager.setCurrentItem(2, true);
有人知道如何做到这一点吗?
Does anyone know how to accomplish this?
推荐答案
我遇到了同一问题。
以下是我的结论:
I have come across the same issue. the following is my conclusion:
当页面实际更改时,将调用onPageSelected。
但它在动画之前被调用。
When the page is actually changed onPageSelected will be called. But it's called before the animation.
动画停止后,将以状态SCROLL_STATE_IDLE调用onPageScrollStateChanged。
When the animation stopped , onPageScrollStateChanged will be called with state SCROLL_STATE_IDLE.
因此,您必须结合这两个函数调用才能调用函数。
So you have to combine this two function calls to get your function called.
祝你好运。
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();//this will be called when animation ends
isPageChanged = false;
}
break;
case ViewPager.SCROLL_STATE_DRAGGING:
break;
case ViewPager.SCROLL_STATE_SETTLING:
break;
}
}
}
这篇关于Android ViewPager动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文