Home > Back-end >  ObjectAnimators are two times faster then the given duration - Android
ObjectAnimators are two times faster then the given duration - Android

Time:10-07

I have a translate animation like this

fun createTranslateAnimation(fromX: Float, toX: Float, fromY: Float, toY: Float):
        ObjectAnimator {
    val propertyValuesX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, fromX, toX)
    val propertyValuesY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, fromY, toY)

    return ObjectAnimator.ofPropertyValuesHolder(imageView,
        propertyValuesX,
        propertyValuesY)
        .apply {
            duration = 3000
        }
}

I specified the duration 3000ms. But when I run the app, the animation is executing 2 times faster. So I've put some logs like this.

val objectAnim = createTranslateAnimation(xValueFrom, xValueTo, yValueFrom, yValueTo)
    objectAnim.apply {
        doOnStart {
            time = System.currentTimeMillis()
        }
        doOnEnd {
            val elapsedTime = System.currentTimeMillis() - time
            Log.d("$elapsedTime seconds")
        }
        start()
    }

At the end the result is - 1518 seconds

What am I doing wrong? If I specify the duration of 3000ms, why is it executing two times faster?

CodePudding user response:

It sounds like Animation duration scale setting in device's Developer options section is changed. As far as I know once the Developer options and some setting or value is changed there is nothing you can do so the system doesn't take it in consideration.

  • Related