Adh*_*ham 8 animation android easing-functions easing
我想使用自定义功能的自定义应用animation
Android view
(按钮)上的翻译interpolator
:
public static float easeOut(float t,float b , float c, float d) {
if ((t/=d) < (1/2.75f)) {
return c*(7.5625f*t*t) + b;
} else if (t < (2/2.75f)) {
return c*(7.5625f*(t-=(1.5f/2.75f))*t + .75f) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625f*(t-=(2.25f/2.75f))*t + .9375f) + b;
} else {
return c*(7.5625f*(t-=(2.625f/2.75f))*t + .984375f) + b;
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个使用自定义插补器的示例,如下所示:
插值器是:
public class HesitateInterpolator implements Interpolator {
public HesitateInterpolator() {
}
public float getInterpolation(float t) {
float x = 2.0f * t - 1.0f;
return 0.5f * (x * x * x + 1.0f);
}
}
Run Code Online (Sandbox Code Playgroud)
并像这样使用:
ScaleAnimation anim = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
anim.setInterpolator(new HesitateInterpolator());
Run Code Online (Sandbox Code Playgroud)
我的问题是:什么是这些值b
,c
,d
为?
Fra*_*rmu 14
仅供参考:对于那些只想要一个简易插补器的人来说,你可以使用它 myAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
dai*_*jia 12
我创建了一个可以解决这个问题的库.AndroidEasingFunctions
ʞᴉɯ*_*ʞᴉɯ 10
据罗伯特·彭纳的缓动函数,如规定在这里:
t:当前时间,b:begInnIng值,c:变化值,d:持续时间
如果你想实现你的自定义插值器,你必须做这样的事情:
(这将是实施easeInOutQuint
)
public class MVAccelerateDecelerateInterpolator implements Interpolator {
// easeInOutQuint
public float getInterpolation(float t) {
float x;
if (t<0.5f)
{
x = t*2.0f;
return 0.5f*x*x*x*x*x;
}
x = (t-0.5f)*2-1;
return 0.5f*x*x*x*x*x+1;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:要实现缓动函数,您需要一些数学知识,考虑到该getInterpolation
方法只获得t参数,从0.0到1.0.
所以基本上你需要开发ay(t)函数,t从0到1,y值从0到1,如下所示:
你改变的是从0到1的曲线(在图像中,绿线是线性的,例如).您需要将缓动函数"标准化"以保留在(0,1)x(0,1)方格中,如我在easeInOutQuint
实现中所见.
归档时间: |
|
查看次数: |
17391 次 |
最近记录: |