I am working on a kotlin Project and i try to convert a method in java to kotlin. I am now getting this error
None of the following functions can be called with the arguments supplied.
it occurs on the ObjectAnimator.ofFloat()
The Code is below
Code
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()
}
Seemingly, the error is caused by the fact that Kotlin, unlike Java, does not promote integer literals to floating point types. You have to write them as, for example, 200f
, and fix these two lines:
val objectY = ObjectAnimator.ofFloat(holder.itemView, View.TRANSLATION_Y, if (goesDown) 200f else -200f, 0f)
val objectX = ObjectAnimator.ofFloat(holder.itemView, View.TRANSLATION_X, -50f, 50f, -30f, 30f, -20f, 20f, -5f, 5f, 0f)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With