android animate() withEndAction() vs setListener() onAnimationEnd()

£可爱£侵袭症+ 提交于 2019-12-03 09:45:33

There is no big difference, take a look at the souce code.

Both are executed on onAnimationEnd.

But the runnable gets removed after it was started. So The Runnable is just executed once and the Listener might be called multiple times.

@Override
public void onAnimationEnd(Animator animation) {
    mView.setHasTransientState(false);
    if (mListener != null) {
        mListener.onAnimationEnd(animation);  // this is your listener
    }
    if (mAnimatorOnEndMap != null) {
        Runnable r = mAnimatorOnEndMap.get(animation); // this is your runnable
        if (r != null) {
            r.run();
        }
            mAnimatorOnEndMap.remove(animation);
    }
    if (mAnimatorCleanupMap != null) {
        Runnable r = mAnimatorCleanupMap.get(animation);  
        if (r != null) {
            r.run();
        }
        mAnimatorCleanupMap.remove(animation);
    }
    mAnimatorMap.remove(animation);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!