如何创建自定义插值器以在android中应用翻译动画

问题描述 投票:3回答:2

我想创建一个自定义插值以应用翻译动画,其中动画应通过以下功能:

  public static float easeIn(float t,float b , float c, float d) {
                return c*(t/=d)*t + b;
        }

其中:

t: current time
b: start value
c: change in value
d: duration 

我发现了一种可以实现比例动画的方法,如果仅采用一个参数:

import android.view.animation.Interpolator;

public class MyInterpolator implements Interpolator {
    public MyInterpolator() {
    }

    public float getInterpolation(float t) {
        float x = 2.0f * t - 1.0f;
        return 0.5f * (x * x * x + 1.0f);
    }
}

如何使用上述函数进行插值创建以进行翻译。

java android animation translate-animation interpolation
2个回答
5
投票

简短的回答:从我的名字来看,您的easyIn应该是AccelerateInterpolator

您编写的函数不是插值器可以执行的功能。插值器并不关心它是Scale,Alpha还是TranslateAnimation。该文档解释了Interpolator getInterpolation像这样:介于0和1.0之间的值表示动画中的当前点,其中0表示开始,而1.0表示结束]

插值器提供了从过去的时间(相对)映射到动画进度的功能。您可以用%来想象它,getInterpolation(xy)会告诉您“如果通过了总持续时间的xy%,则应该通过多少百分比的总动画?”

以LinearInterpolator为例。该实现将如下所示:

public float getInterpolation(float t) {
        return t
}

示例:使用LinearInterpolator从0px动画到200px:经过45%(0.45)的时间后,应传递45%(返回0.45)的动画,即90px(200px * 0.45)

请阅读此以获取详细信息:

Android Animations Tutorial 5: More on Interpolators


0
投票

访问https://matthewlein.com/tools/ceaser通过操纵图表而不是复制线条[]下的值来创建自定义插值器

代码片段,短手和长手:

比使用

Interpolator mInterpolator = PathInterpolatorCompat.create(1.000f, 0.000f, 1.000f, 1.030f)

使用复制的值来创建您的自定义插值器

© www.soinside.com 2019 - 2024. All rights reserved.