我有下面的代码(在斯卡拉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