代码之家  ›  专栏  ›  技术社区  ›  Rgfvfk Iff

动画视图宽度

  •  0
  • Rgfvfk Iff  · 技术社区  · 7 年前

    是否可以控制具有的视图的宽度动画 wrap_content TextView 右边有个障碍物。我有另一个背景 View 与这个屏障一致。当 文本框 animateLayoutChanges

    1 回复  |  直到 7 年前
        1
  •  1
  •   Prithvi Bhola    7 年前

    ObjectAnimator 随着 AnimatorSet

    extension 在里面 kotlin 对于 view 要在其上应用动画。

    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()
    }