当我在自定义视图中运行此代码时,onAnimationStart
和onAnimationEnd
将不断重复调用。这不奇怪吗?作为一名Android程序员,我希望他们分别只被调用一次。无法删除ViewPropertyAnimator的监听器
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
得到通过的setListener(null)
ViewPropertyAnimator
调用,但它从来没有工作,尽管什么写在文档:
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的错误?
你在哪里调用animator.start()? – pskink 2015-04-02 08:00:25
在我的自定义视图,顺便说一句,其实,我想我甚至不需要调用它,动画将由下一个机会(也许下一帧)开始。我在文档 – Leo 2015-04-02 08:06:04
的某个地方阅读它“在我的自定义视图中”是什么?什么方法? – pskink 2015-04-02 08:10:11