ViewPropertyAnimator's alpha animation does not work

453 views Asked by At

I use ViewPropertyAnimator for creating alpha animations. Both withStartAction() and withEndAction() work great, alpha values changed, but they changed in no time, looks like there is no animation, just changing values. Where is a mistake?

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 }
            }
}
0

There are 0 answers