我使用ViewPropertyAnimator创建alpha动画。 withStartAction()和withEndAction()都工作得很好,alpha值发生了变化,但是它们很快就改变了,看起来没有动画,只是改变了值。哪里出错?
private fun run(millisecondsPerPixel: Long) { //millisPerPixel=30
pixelsToCenter = (_endHeight - _startHeight - emptyPlaceOffset) / 2.toLong() // 15
val duration = millisecondsPerPixel * pixelsToCenter // 450
val animator = if (opening) mainLayout!!.animate() else secondaryLayout!!.animate()
animator.alpha(0.0F).setDuration(duration)
.withStartAction {
changing = true
val resize = if (opening) ResizeAnimation(this@CustomToolbar, height, _endHeight) else
ResizeAnimation(this@CustomToolbar, height, _startHeight)
resize.duration = millisecondsPerPixel * (_endHeight - _startHeight)
startAnimation(resize) // this one works like a charm
}
.withEndAction {
val backAnimator = if (opening) {
mainLayout!!.visibility = View.GONE
secondaryLayout!!.animate()
} else {
secondaryLayout!!.visibility = View.GONE
mainLayout!!.animate()
}
backAnimator.alpha(1.0F).setDuration(duration)
.setStartDelay(millisecondsPerPixel * emptyPlaceOffset)
.withStartAction {
if (opening) secondaryLayout!!.visibility = View.VISIBLE else mainLayout!!.visibility = View.VISIBLE
}
.withEndAction { changing = false }
}
}