Android property animation: how to increase view height?

后端 未结 7 2180
不知归路
不知归路 2020-12-07 20:17

How to increase the view height using Property Animations in Android?

ObjectAnimator a = ObjectAnimator.ofFloat(viewToIncreaseHeight, \"translationY\", -100)         


        
7条回答
  •  自闭症患者
    2020-12-07 20:33

    Use this method in kotlin:

    private fun increaseViewSize(view: View) {
        val valueAnimator = ValueAnimator.ofInt(view.measuredHeight, view.measuredHeight+20)
        valueAnimator.duration = 500L
        valueAnimator.addUpdateListener {
            val animatedValue = valueAnimator.animatedValue as Int
            val layoutParams = view.layoutParams
            layoutParams.height = animatedValue
            view.layoutParams = layoutParams
        }
        valueAnimator.start()
    }
    

提交回复
热议问题