Animate the rotation of the Marker in google map v2

后端 未结 8 1976
感情败类
感情败类 2020-12-16 07:19

i am using google maps v2. i have a marker on map, this marker changes rotation every while. I want to animate the rotation of my maker to rotate smoothly. Can anyone help p

8条回答
  •  孤城傲影
    2020-12-16 07:28

    The answer from Alexandr Kolesnik seems to be the most simple. Here's a Kotlin extension version of it.
    You can pass in an interpolator to avoid a little thrash.

    fun Marker.animateRotation(toRotation: Float, interpolator: TimeInterpolator? = AccelerateDecelerateInterpolator()) {
        val animator = ValueAnimator.ofFloat(rotation, toRotation)
        animator.duration = 500
        animator.interpolator = interpolator
        animator.addUpdateListener {
            rotation = it.animatedValue as? Float ?: return@addUpdateListener
        }
    
        animator.start()
    }
    

提交回复
热议问题