Android 具有自定义属性的ObjectAnimator不调用属性设置器

Android 具有自定义属性的ObjectAnimator不调用属性设置器,android,animation,kotlin,Android,Animation,Kotlin,我想使用自定义属性设置自定义视图位置的动画,如下所示: class ProgressFab : ImageView { // constructors ... etc val path = Path() init { path.moveTo(0f, 0f) path.lineTo(700f, 500f) } @SuppressWarnings("unused") public fun setFubPositi

我想使用自定义属性设置自定义视图位置的动画,如下所示:

class ProgressFab : ImageView {

    // constructors ... etc

    val path = Path()

    init {
        path.moveTo(0f, 0f)
        path.lineTo(700f, 500f)
    }

    @SuppressWarnings("unused")
    public fun setFubPosition(path: FloatArray) {
        this.x = path[0]
        this.y = path[1]
    }

    fun startMotion() {
        val animator = ObjectAnimator.ofMultiFloat(this, "fubPosition", path)
        animator.duration = 5000

        animator.addUpdateListener {
//(1)       this.x = (it?.animatedValue as FloatArray)[0]
//(2)       this.y = (it?.animatedValue as FloatArray)[1]
            invalidate()
        }

        animator.start()
    }
}
调用
startMotion()
animator后启动,但
setFubPosition(路径:FloatArray)
未调用。如果我取消注释(1)和(2),所有操作都正常

这是反编译的kotlin字节码(看起来都不错):

如果我尝试使用
offload
方法设置自定义属性的动画,则属性设置器工作正常:

val animator = ObjectAnimator.ofFloat(this, "fubPosition", 0f, 100f);
在kotlin中,是否可以使用multifloat的
或multiint的
方法使用property setter自动更改属性?

来自您获得的文档

在这种变化中,坐标是分别在setter的第一个和第二个参数中使用的浮动x和y坐标

因此,不支持将数组作为属性的参数,但支持多个参数。只需更改设定者的签名以反映此要求:

@SuppressWarnings("unused")
public fun setFubPosition(x: Float, y: Float) {
    this.x = x
    this.y = y
}

调用
animator.start()
后,您在logcat上看到了什么?与动画无关。因为动画开始了,如果我将
Log.d()
添加到
addUpdateListener
中,并显示
animatedValue
,它将显示在logcat中。你没有任何
方法()在目标类上找不到类型
警告吗?没有,没有(在清除logcat并运行方法后,没有类似的内容)调用
ObjectAnimator.offload(这个“foo”、0f、100f)时再次检查日志猫-在目标类上没有找到任何类型为float的
方法setFoo…
?如果你没有看到它,你的logcat会过滤掉一些非常简单的日志!在java中,这可以正常工作,但在kotlin代码中,lint show error:
此属性的setter与预期的签名不匹配(public void setFubPosition(float[]arg)(此处的属性setter)
。由于此错误消息,我没有运行此代码。但现在我运行了,所有的工作(error msg仍然存在)!谢谢!
@SuppressWarnings("unused")
public fun setFubPosition(x: Float, y: Float) {
    this.x = x
    this.y = y
}