Android 中如何将插值器与动画一起使用?
How can an Interpolator be used with an animation in Android?
我有以下代码:
ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).start();
我想在 ObjectAnimator
中添加一个 Interpolator
;但是,当我使用以下代码时,我收到一条错误消息,指出 "Can not call start() on primitive type void":
ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).setInterpolator(new BounceInterpolator()).start();
如何将 Interpolator
与 ObjectAnimator
一起使用?
谢谢!
错误是因为 setInterpolator()
没有 return 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();
我有以下代码:
ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).start();
我想在 ObjectAnimator
中添加一个 Interpolator
;但是,当我使用以下代码时,我收到一条错误消息,指出 "Can not call start() on primitive type void":
ObjectAnimator.ofInt(this, "barHeight", maxInPx).setDuration(1000).setInterpolator(new BounceInterpolator()).start();
如何将 Interpolator
与 ObjectAnimator
一起使用?
谢谢!
错误是因为 setInterpolator()
没有 return 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();