Android property animation: how to increase view height?

后端 未结 7 2203
不知归路
不知归路 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:28

    For kotlin you can use this method

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

    It will increase view's size as defined in parameter

    based on @Minion answer

提交回复
热议问题