如何prepare曲线转换动画的android? [英] How to prepare curve translate animation for android?

查看:181
本文介绍了如何prepare曲线转换动画的android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有4种类型的机器人动画 - 旋转,阿尔法,规模和翻译。 我想prepare曲面转换动画。

There are 4 types of animations in android - rotate, alpha,scale and translate. I want to prepare curved translate animation.

是否有可能?

推荐答案

你用什么Android版本?由于API级别11,你可以使用自定义动画制作,可以轻松实现你的曲线平移。

What Android version do you use? Since API level 11 you can use custom Animators which can easily implement your curve translation.

如果您使用以下一个版本有AFAIK只有使用翻译动画和设置动画的听众手动连接多个线性转换的可能性

If you use a version below that there is afaik only the possibility to manually concatenate multiple linear translations using the translate animation and setting animation listeners

编辑:

例如:

View view;
animator = ValueAnimator.ofFloat(0, 1); // values from 0 to 1
animator.setDuration(5000); // 5 seconds duration from 0 to 1
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        float value = ((Float) (animation.getAnimatedValue()))
                    .floatValue();
        // Set translation of your view here. Position can be calculated
        // out of value. This code should move the view in a half circle.
        view.setTranslationX((float)(200.0 * Math.sin(value*Math.PI)));
        view.setTranslationY((float)(200.0 * Math.cos(value*Math.PI)));
    }
});

我希望它的工作原理。只需复制和放大器;粘贴(缩短和改变),从我的应用程序之一的code。

I hope it works. Just copied & pasted (and shortened and changed) the code from one of my apps.

这篇关于如何prepare曲线转换动画的android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆