android - 如何在 Kotlin 中为 ObjectAnimator 添加监听器?

标签 android kotlin objectanimator

我做了这样的事情

val animator = ObjectAnimator.ofFloat(view, "translationY", 350f,0f)
    animator.duration = 500
    animator.startDelay=200
    animator.interpolator =AccelerateDecelerateInterpolator()
    animator.start()

现在我正在尝试向该适配器添加监听器。 这个我试过了,

animator.addListener(onStart = {view.visibility=View.VISIBLE})

但是没有用。

最佳答案

虽然您的问题不清楚,因为您没有提到什么不起作用。我猜你的听众没用。

您正在启动动画器,然后添加它,这当然永远不会被调用。

更改如下:

val animator = ObjectAnimator.ofFloat(view, "translationY", 350f, 0f)
animator.apply {
    duration = 500
    startDelay = 200
    addListener(onStart = {
        view.visibility = View.VISIBLE
    })
    AccelerateDecelerateInterpolator()
    start()
}

关于android - 如何在 Kotlin 中为 ObjectAnimator 添加监听器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58214142/

相关文章:

android - 用户 10051 和当前进程都没有 android.permission.INSTALL_PACKAGES

android - 我如何使用 Android 存储库中的流程?

android - 我如何将变量从我的适配器传递到我在 Kotlin 中实例化的 fragment

java - Android 对象动画 xml

android - 为什么objectAnimator不调用setter方法

android - 使用没有运行的 Eclipse 重建 .apk

android - 应用程序在启动时意外停止

安卓-Gradle : Copy to native-libs

kotlin - 分号推理的规则是什么?

java - Android Studio 使用 ObjectAnimation 制作动画