如何在 Android 中的视图上应用缓动动画功能 [英] How to apply easing animation function on view in Android
本文介绍了如何在 Android 中的视图上应用缓动动画功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用自定义 interpolator
在 Android view
(按钮)上应用翻译 animation
,其中缓动功能是:>
public static float easeOut(float t,float b, float c, float d) {如果 ((t/=d) <(1/2.75f)) {返回 c*(7.5625f*t*t) + b;} else if (t <(2/2.75f)) {返回 c*(7.5625f*(t-=(1.5f/2.75f))*t + .75f) + b;} else if (t <(2.5/2.75)) {返回 c*(7.5625f*(t-=(2.25f/2.75f))*t + .9375f) + b;} 别的 {返回 c*(7.5625f*(t-=(2.625f/2.75f))*t + .984375f) + b;}}
我有一个使用自定义插值器的示例:
内插器是:
public class HesiateInterpolator 实现 Interpolator {公共犹豫插值器(){}公共浮动 getInterpolation(浮动 t){浮动 x = 2.0f * t - 1.0f;返回 0.5f * (x * x * x + 1.0f);}}
并像这样使用:
ScaleAnimation anim = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);anim.setInterpolator(new HesitateInterpolator());
我的问题是:b
、c
、d
这些值是什么意思?
解决方案
仅供参考:对于那些只想要一个简单的插值器的人,你可以使用 myAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
>
I want to apply a translate animation
on an Android view
(button) using a custom interpolator
where the easing function is:
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;
}
}
I have an example that uses the custom interpolator like this:
The interpolator is:
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);
}
}
and is used like this:
ScaleAnimation anim = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
anim.setInterpolator(new HesitateInterpolator());
My question is:
What are these values b
, c
, d
for?
解决方案
FYI: for people who just want an ease interpolator you can just use myAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
这篇关于如何在 Android 中的视图上应用缓动动画功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文