- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在开发一个 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 不同,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)
关于android - ObjectAnimator.ofFloat 不能直接在kotlin中取Int作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44850128/
我有一组 View 能够在屏幕上向下移动并随后反向移动,但现在当我尝试移动 CardView 时,它会向下移动但不会向上移动。 当用户单击按钮时,它会提示 View 集合下拉/消失,当用户再次单击该按
这是我的对象动画师 xml //Animating the NormalLayout final ObjectAnimator anim4 = (ObjectAnimator) //Ob
我有一个 View (sendSidePanel),我在呈现 View 时将其隐藏: public void setListnerToRootView(){ final View activit
我正在使用 kotlin 解构声明。我之前将它与 SpringAnimation 一起使用,并且效果很好。现在我想将它与 ObjectAnimator 一起使用,但出现此错误: Destructuri
我正在尝试为进度条设置动画,以便线性填充需要 1 分钟。 这是我的代码: animator = ObjectAnimator.ofInt(progress_bar, "progress", 0, 10
我尝试在谷歌和各种堆栈问题中四处寻找,但似乎找不到与我正在做的事情相似的东西。 基本上,我只想在动画的某个偏移量处开始给定的 ObjectAnimator 动画(例如,通过动画 30%,或通过动画 7
起初,我以为我的动画根本不起作用,因为新的 Fragment ViewGroup 只会在一帧中出现在屏幕上。然后我放慢了动画速度,所以它需要 3 秒(3000 毫秒)并发现它只是以如此大的 block
我有一个包含 HorizontalScrollView 的 Activity 。 HorizontalScrollView 中有三个 fragment 。单击按钮时, ScrollView 将
我今天设计了两个可绘制的经典arrow 和hamburger 图标来重新创建和理解android 中的objectAnimator。当没有播放动画但更改了可绘制对象时会出现此问题。 我已经创建了 ic
我使用 ObjectAnimator API (android.animation.ObjectAnimator) 在按钮被点击后设置动画(v 是按钮): ObjectAnimator animato
我想要一个相对布局来放大并且 View 的底部应该是固定的。 我有一个相对布局 - private RelativeLayout rlOutdoorSection; 初始化它- rlOutdoorSe
我正在尝试查找 ObjectAnimator 可以设置动画的属性列表以及它如何设置动画。 例如,我想知道 translationY 属性是如何设置动画的。该值是要坐标还是距离? 最佳答案 Object
我正在尝试使用 Animator 集顺序播放一组动画。除了 alpha 动画 (set1) 外,一切正常。它从 0.25f 变为 1,但在整个动画中并没有消失,并且在 set1 动画结束时,它从 0.
我需要将按钮从一个位置移动到另一个位置。 View 位置移动工作正常,但只有旧区域是可点击的。 这是我的代码: Button animatorButton = (Button)findViewByI
我尝试制作ImageView 的扩展布局动画和平移 动画,但我同时启动它们时它们看起来有点滞后。我在真实设备 Moto X(2013) 上对其进行了测试。不确定更强大的设备,因为默认情况下我所有的模拟
我想使用 ObjectAnimator 在 Y 轴上移动一个 textView。这段代码有效,但由于屏幕尺寸的原因,它并不适合所有设备。 ObjectAnimator mover = Objec
我使用 Animator XML 为 ImageView 设置动画。 ImageView 应该增长(从 0f 到 1f,Y 比 X 快)并从 90 旋转 90° 到 0。我将此 XML 文件用于动画:
我正在使用 ObjectAnimator 滚动 HorizontalScrollView(左 -> 右 -> 左)。因此,结果应该是从一侧无限滚动到另一侧。 问题 是在我开始向右 -> 左设置动画
我正在尝试使用 ObjectAnimator 来制作向上滑动的翻译动画,因为我们知道,如果我们像这样使用普通的翻译动画,onclicklistener 将无法工作, 上面的 xml 代码工作正常,但
如果属性 x 被指定为字符串,ObjectAnimator 如何能够调用适当的方法 setX?我的意思是,使用什么技术来识别我想要为 View 的属性 rotation 设置动画并调用该 View 的
我是一名优秀的程序员,十分优秀!