如何设置 PropertyAnimation 的帧速率?

How do you set the frame rate for PropertyAnimation?

Android documentation 表示可以设置刷新率:

Frame refresh delay: You can specify how often to refresh frames of your animation. The default is set to refresh every 10 ms, but the speed in which your application can refresh frames is ultimately dependent on how busy the system is overall and how fast the system can service the underlying timer.

但是,它并没有告诉您如何操作。到处都找遍了,在ObjectAnimator、PropertyAnimator、Animator中都没有这个方法

编辑:我目前使用的是每 5 帧仅响应一次的动画更新程序 -

colorFade.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
       int interpolator = 0;

       @Override
       public void onAnimationUpdate(ValueAnimator animation) {
           if ((interpolator++) % 5 == 0)
                invalidate(mHandlerBounds);
        }
  });

正如@pskink 所说,使用:

public static void setFrameDelay(long frameDelay)

ValueAnimator class。你可以在文档中看到这个:

The amount of time, in milliseconds, between each frame of the animation. This is a requested time that the animation will attempt to honor, but the actual delay between frames may be different, depending on system load and capabilities. This is a static function because the same delay will be applied to all animations, since they are all run off of a single timing loop. The frame delay may be ignored when the animation system uses an external timing source, such as the display refresh rate (vsync), to govern animations.

您可以对用户实施TimeInterpolator interface to create a custom Interpolator, map the elapsed fraction to a new fraction that represent the frame rate. For example, I want to rotate a loading image view to show loading indication

ObjectAnimator animator = ObjectAnimator.ofFloat(loadingView, "rotation", 360f);
animator.setDuration(600);
animator.setInterpolator(new TimeInterpolator() {
    @Override
    public float getInterpolation(float input) {
        return (int)(input * 12) / 12.0f;
    }
});
animator.start();

在该示例中,loadingView 将在 600 毫秒内旋转 360 度。默认帧速率为 (1000ms / 10ms)。如果我不设置自定义Interpolator,loadingView会旋转得非常快,导致loadingView变成一个圆圈而不是指示。我需要使帧速率等于加载图像的 "leap",即 12.

我将动画持续时间映射到12个部分,接收到的经过部分将映射到包含该部分的部分。

所以,只需将 12 更改为您想要的帧率应该在您的代码中,即可实现最终的帧率。