當我在自定義視圖中運行此代碼時,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