Android property animation: how to increase view height?

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

    Here is my code to animate scrolling an item to center of the screen inside a recycleView

    // Scrolling with animation
    val valueAnimator = ValueAnimator.ofInt(getWidth() / 2)
    valueAnimator.duration = 250L
    valueAnimator.addUpdateListener {
        val animatedValue = valueAnimator.animatedValue as Int
        (layoutManager as LinearLayoutManager).scrollToPositionWithOffset(itemToScroll, animatedValue)
    }
    valueAnimator.start()
    // End of scrolling with animation
    

    Note it is a bit similar to UIView.animate in Swift, but with more complication

提交回复
热议问题