点击按钮时调用的动画:
confirmBtn.setOnClickListener {
finalWalkthroughViewModel.setConfirmation(true)
it.hide()
deliveredView.show()
validateForm()
}
我的扩展程序在View上起作用:
fun View.hide(visibility: Int = android.view.View.GONE) {
this.alpha = 1.0f
this.animate().alpha(0.0f).setDuration(ANIMATION_TIME)
.setListener(object : Animator.AnimatorListener {
override fun onAnimationRepeat(animation: Animator?) {
}
override fun onAnimationEnd(animation: Animator?) {
this@hide.visibility = visibility
}
override fun onAnimationCancel(animation: Animator?) {
}
override fun onAnimationStart(animation: Animator?) {
}
})
}
fun View.show() {
this.alpha = 0.0f
this.visibility = View.VISIBLE
this.animate().alpha(1.0f).setDuration(ANIMATION_TIME).setListener(null)
}
因此,如果我从.setListener(null)
中删除show()
,则会调用先前在hide函数中设置的侦听器。为什么会这样? android中的动画实现是否包含伴随对象或单例类?