Java 具有两个插值器的动画
我需要使用两个插值器制作动画,例如,动画的持续时间为1秒,持续时间为0秒到0.5秒,使用加速插值器,持续时间为0.5秒到1秒,使用反弹插值器Java 具有两个插值器的动画,java,android,animation,interpolation,Java,Android,Animation,Interpolation,我需要使用两个插值器制作动画,例如,动画的持续时间为1秒,持续时间为0秒到0.5秒,使用加速插值器,持续时间为0.5秒到1秒,使用反弹插值器 有办法做到这一点吗?您可以尝试以下方法: <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
有办法做到这一点吗?您可以尝试以下方法:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:interpolator="@android:anim/bounce_interpolator"
android:fromYDelta="0%p"
android:toYDelta="100"
android:duration="500"/>
<translate
android:interpolator = "@android:anim/accelerate_interpolator"
android:fromYDelta="100"
android:toYDelta="100"
android:fromXDelta="0"
android:toXDelta="100"
android:startOffset="500"
android:duration="1000"/>
</set>
这使用了两个
插值器
,第一个是将视图移动一半秒的反弹。第二个插值器
是一个加速插值器
,它在减半秒后将视图向右移动一秒钟。因此,总动画时间为1秒。希望有帮助 我只使用一个动画:
Animation animation = new TranslateAnimation(0,100,0,0);
animation.setDuration(1000);
pointerAnimation.setInterpolator(new CustomBounceInterpolator(500));
view.startAnimation(animation);
以及CustomInterpolator类:
public class CustomBounceInterpolator implements Interpolator {
private float timeDivider;
private AccelerateInterpolator a;
private BounceInterpolator b;
public CustomBounceInterpolator(float timeDivider) {
a = new AccelerateInterpolator();
b = new BounceInterpolator();
this.timeDivider = timeDivider;
}
public float getInterpolation(float t) {
if (t < timeDivider)
return a.getInterpolation(t);
else
return b.getInterpolation(t);
}
}
公共类CustomBounceInterpolator实现插值器{
专用浮点分时器;
专用加速器内极器a;
专用弹跳器b;
公共自定义BounceInterpolator(浮动计时器){
a=新的加速器内极器();
b=新的反弹内极器();
this.timeDivider=分时器;
}
公共浮点(浮点t){
if(t<分时器)
返回a.get插值(t);
其他的
返回b.t(t);
}
}
您好在示例中,匿名类失败
不是这样:pointerAnimation.setInterpolator(新的CustomInterpolator(500))代码>
就是这样:pointerAnimation.setInterpolator(新的CustomBounceInterpolator(500))代码>
无论如何,非常感谢帮助了我很多这里有两个插值器,但是有太多的两个动画,这是可行的,但是如果只是一个动画,那么在3个简单的步骤中,定制插值器可能会更好一些。。