ObjectAnimator.ofFloat不能直接在kotlin中将Int作为参数

我正在kotlin项目上工作,我尝试将java中的方法转换为kotlin。 我现在得到这个错误

所提供的参数都不能调用以下函数。

它发生在ObjectAnimator.ofFloat()

代码如下

 fun animate(holder: RecyclerView.ViewHolder, goesDown: Boolean) { val animat = AnimatorSet() val objectY = ObjectAnimator.ofFloat(holder.itemView, "translationY", if (goesDown) 200 else -200, 0) objectY.setDuration(Kons.Duration.toLong()) val objectX = ObjectAnimator.ofFloat(holder.itemView, "translationX", -50, 50, -30, 30, -20, 20, -5, 5, 0) objectX.setDuration(Kons.Duration.toLong()) animat.playTogether(objectX, objectY) animat.start() } 

看起来,这个错误是由于Kotlin不像Java 那样将整数文字提升为浮点类型而造成的 。 你必须把它们写成例如200f ,然后修正这两行:

 val objectY = ObjectAnimator.ofFloat(holder.itemView, "translationY", if (goesDown) 200f else -200f, 0f) 

 val objectX = ObjectAnimator.ofFloat(holder.itemView, "translationX", -50f, 50f, -30f, 30f, -20f, 20f, -5f, 5f, 0f)