我正在从事一个kotlin项目,我试图将java中的一个方法转换为kotlin.

None of the following functions can be called with the arguments supplied.

它发生在ObjectAnimator.ofFloat()

代码如下

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()
}

推荐答案

看起来,这个错误是由于Kotlin与Java不同,它是does not promote integer literals to floating point types.例如,您必须将它们写成200f,并修复以下两行:

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)

Kotlin相关问答推荐

Android Studio中的只读集合不支持操作失败的原因是什么?

有没有一种简单的方法来识别物体?

为什么使用 return instance ?: synchronized(this) { instance ?: PreferenceParameterState(context) } 时无法获得单例?

如何获取@JsonProperty 名称列表?

Kotlin 协程按顺序执行,但仅在生产机器上执行

Kotlin 列表扩展功能

PRDownloader 即使在实现库后也无法工作.未知参考:Android Studio 中的 PRDownloader

添加 Kapt 插件后 - 执行 org.jetbrains.kotlin.gradle.internal.KaptExecution 时发生故障

为什么 IntelliJ Idea 无法识别我的 Spek 测试?

Hilt Activity 必须附加到 @AndroidEntryPoint 应用程序

Kotlin:找不到符号类片段或其他 android 类

为什么 Kotlin Pair 中的条目不可变?

Kotlin:sealed class cannot "contain" data classes?

如何将命令行参数传递给Gradle Kotlin DSL

如何捕获传递给模拟函数的参数并返回它?

如何从kotlin中的类实例化对象

在多平台子元素中使用kapt

如何在 kotlin 中创建重复对象数组?

Kotlin - 为什么我会得到 KotlinNullPointerException

类型推断失败:RecyclerViewActions.scrollTo()