当我在自定义视图中运行此代码时,onAnimationStart
会onAnimationEnd
不断被调用。这不是很奇怪吗?作为一名 Android 程序员,我希望它们分别只被调用一次。
final ViewPropertyAnimator animator = animate().setDuration(1000).alpha(0.0f); animator.setListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { Utils.log("----------------start"); } @Override public void onAnimationEnd(Animator animation) { Utils.log("--------- end"); } }).start();
但是后来我尝试通过在onAnimationEnd
被ViewPropertyAnimator
's调用时删除侦听器来解决问题,setListener(null)
但是尽管文档中写了,但它从未起作用:
public ViewPropertyAnimator setListener (Animator.AnimatorListener listener)
Added in API level 12
Sets a listener for events in the underlying Animators that run the property animations.
Parameters
listener The listener to be called with AnimatorListener events. A value of null removes any existing listener.
Returns
This object, allowing calls to methods in this class to be chained.
有没有其他人遇到过这个奇怪的问题?也许这是Android的错误?