在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();