是否可以控制具有的视图的宽度动画wrap_content?现在我的TextView右侧有一个障碍物。我有另一个View与这个障碍一致的背景。当TextView更改文本时,它只是闪烁到新的宽度,但我想用一个动画器为宽度设置动画,在那里我可以控制时间、插值器等。我知道我可以设置类似的东西,animateLayoutChanges但效果是不可定制的。
1 回答
1
您可以ObjectAnimator与动画一起使用AnimatorSet。
这是您要在其上应用动画的extensionin 。kotlinview
inline fun View.animateWidth(duration: Long = 1000, startDelay: Long = 0) {
val scaleX = ObjectAnimator.ofFloat(this, "scaleX", /*Change width*/)
//val scaleY = ObjectAnimator.ofFloat(this, "scaleY", /*Change width*/)
val set = AnimatorSet()
//set.playTogether(scaleX, scaleY)
set.playTogether(scaleX)
set.duration = duration
set.startDelay = startDelay
set.interpolator = LinearInterpolator()
set.addAnimatorListener(
onStart = { this.isClickable = false },
onEnd = { this.isClickable = true }
)
set.start()
}
于 2018-10-04T06:54:00.730 回答