我有下面的代碼(在斯卡拉Android項目):我可以重複使用ValueAnimator嗎?
val animator = new ValueAnimator
animator.setFloatValues(0f, 100f)
animator.setDuration(20000L)
animator.addUpdateListener(this) // prints current value to console
animator.start
override def onTouch(v: View, event: MotionEvent) = {
animator.setFloatValues(100f, 0f)
animator.setCurrentPlayTime(0)
if (!animator.isRunning) animator.start
true
}
如果我觸摸屏幕,同時animator
運行那麼它是否正確啓動向後工作(因爲我已經換了值)。但是如果我在屏幕完成後觸摸屏幕,則什麼都不會發生,它不會重新開始。
問題是我可以以某種方式重用這個動畫製作器,並且在它停止後給它賦值嗎?
你就是不行。我剛剛檢查過它。我也想在應用程序中重用它。所以使用clone來獲得一個新的實例,然後爲每個實例設置目標視圖。 – Napolean 2015-06-18 08:03:56