在Android中,如何将插值器与动画一起使用?
我有以下代码:在Android中,如何将插值器与动画一起使用?,android,android-animation,Android,Android Animation,我有以下代码: ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).start(); ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).setInterpolator(new BounceInterpolator()).start(); 我想在ObjectAnimator中添加一个插值器;但是,当我使用以下代码时,我收到一个错误
ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).start();
ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).setInterpolator(new BounceInterpolator()).start();
我想在ObjectAnimator
中添加一个插值器
;但是,当我使用以下代码时,我收到一个错误,说明“不能在基元类型void上调用start()”:
ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).start();
ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).setInterpolator(new BounceInterpolator()).start();
如何将插值器
与对象动画器
一起使用
谢谢大家! 错误是因为
setInterpolator()
没有返回ObjectAnimator
实例。您必须分解代码:
ObjectAnimator objectAnimator = ObjectAnimator.ofInt(this, "barHeight", maxInPx);
objectAnimator.setDuration(1000);
objectAnimator.setInterpolator(new BounceInterpolator());
objectAnimator.start();
您可以使用下面的代码将其稍微缩短一点,但这大约是您将得到的代码缩减量
ObjectAnimator objectAnimator = ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000);
objectAnimator.setInterpolator(new BounceInterpolator());
objectAnimator.start();