如何编辑Android动画插值器?

3

我需要制作一个基于比例的动画对话框。我希望能够使用弹跳效果,我尝试过使用弹跳插值器。

<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromXScale="0"
    android:fromYScale="0"
    android:interpolator="@android:anim/bounce_interpolator"
    android:toXScale="1"
    android:toYScale="1" />

我想修改弹跳效果,让它变得更慢/更快,可以控制弹跳的大小。我没有找到任何现成的东西,尝试了使用代码自行调整。
<set >
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="500"
        android:fromXScale="0"
        android:fromYScale="0"
        android:toXScale="1"
        android:toYScale="1" />
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="100"
        android:fromXScale="1"
        android:fromYScale="1"
        android:startOffset="500"
        android:toXScale=".8"
        android:toYScale=".8" />
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="100"
        android:fromXScale=".8"
        android:fromYScale=".8"
        android:startOffset="600"
        android:toXScale="1"
        android:toYScale="1" />
</set>

整个动画表现得很奇怪? 所以我的问题是如何通过设置来修复这个动画,或者如何修改bounce_interpolator?
1个回答

2
使用ipfx.org创建自定义插值器。
将bounce示例编辑为您所需的样式。
http://ipfx.org/?p=7ffffffe575efffe9e02fffed8f6fffe&l=2f13c5ac138b3d6ad338a5a77a8386807d6e
然后在您的应用程序中使用创建的插值器。
import org.ipfx.Interpolator;

...
...

final org.ipfx.Interpolator interpolator = org.ipfx.Interpolator.parseUrl(urlData);

ObjectAnimator animator = ObjectAnimator.ofFloat(...);
animator.setDuration(1000);

animator.setInterpolator(new TimeInterpolator() {
    @Override
    public float getInterpolation(float input) {
        return interpolator.calc(input);
    }
});

animator.start();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接