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()
}
推荐阅读
- visual-studio - 与新网络连接后,IP 地址未更新到 IIS
- android - 带有 Flutter 的动态功能模块
- php - 在每个 require_once 之后添加一个空白文本元素,后跟 1
- qt - 如何从 UART 获取二维数组到 QList
Qt 并在 QML 上设置文本 - postgresql - PostgreSQL 的 pg_stat_all_indexes 表中的统计信息存储多长时间?
- python - 如何正确处理celery任务中出现的python异常?
- visual-studio - 自己的 Nuget 服务器 - '' 处的 V2 提要返回了意外的状态代码 '404 Not Found'
- postman - 在邮递员中读取响应 url 及其查询参数
- docker - Dockerized IBM DB2:未发出启动数据库管理器命令。SQLSTATE=57019
- django - 如何计算两个日期之差的总和