【发布时间】:2020-09-30 10:29:57
【问题描述】:
在 android 上反转动画方向的最佳做法是什么? 另外,我在分析器上跟踪 ram 使用情况,结果是正常的。 我确实喜欢下面的代码:
var flagHeight: Int = 100
private fun startAnimation() {
val animation = tv_hello_world.animate().apply {
translationYBy(flagHeight.toFloat())
setListener(object : Animator.AnimatorListener {
override fun onAnimationStart(p0: Animator?) {
// do nothing
}
override fun onAnimationEnd(p0: Animator?) {
flagHeight = flagHeight.not()
startAnimation()
}
override fun onAnimationCancel(p0: Animator?) {
// do nothing
}
override fun onAnimationRepeat(p0: Animator?) {
// do nothing
}
})
duration = 1000
}
animation.start()
}
fun Int.not() = run { if (this > 0) -this else (this * -1) }
【问题讨论】:
标签: android animation recursion reverse