8

我需要用两个插值器制作动画,例如动画的持续时间为 1 秒,持续时间为 0 秒到 0.5 秒,使用加速插值器 ans 为 0.5 到 1 秒,使用反弹插值器。

有办法做到这一点吗?

4

4 回答 4

13

你可以尝试这样的事情:

<?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>

这使用了两个interpolators,第一个是一个将视图移动半秒的反弹。第二个interpolator是加速interpolator,在半秒过去后将视图向右移动,持续一秒。因此,总动画时间为 1 秒。希望有帮助。

于 2012-08-10T20:39:08.997 回答
11

我只做一个动画:

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);
}

}
于 2012-08-13T14:31:07.683 回答
3

您好,在示例中,匿名类出现故障。

它不是这个:pointerAnimation.setInterpolator(new CustomInterpolator(500));

它是这个:pointerAnimation.setInterpolator(new CustomBounceInterpolator(500));

非常感谢无论如何帮助了我很多

于 2016-06-22T08:06:58.243 回答
0

这篇文章已经很旧了,但是对于下一个登陆这里的人来说:

@ademar111190 的示例不太正确。

getInterpolation(float t)中,t 需要介于0和之间1。这是动画的时间跨度。使用的输入 500 将完全忽略第二个插值器。

这里是文档的链接:时间插值器

于 2021-09-17T13:04:44.897 回答