Android属性动画demo实例(以送花为例)

我的新书《Android App开发入门与实战》已于2020年8月由人民邮电出版社出版,欢迎购买。点击进入详情

文章目录

项目地址

https://github.com/ddnosh/android-demo-animation
在这里插入图片描述

用法

  1. 透明度
		ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(iv, "alpha", 0f, 1f);
        objectAnimator.setDuration(1000);
        objectAnimator.start();
  1. 缩放
		ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(iv, "scaleX", 0f, 1f);
        ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(iv, "scaleY", 0f, 1f);
        AnimatorSet set = new AnimatorSet();
        set.play(scaleXAnimator).with(scaleYAnimator);
        set.setDuration(1000);
        set.start();
  1. 位移
		ObjectAnimator objectAnimatorTranslate = ObjectAnimator.ofFloat(iv, "translationX", 0f, 500f);
        objectAnimatorTranslate.setDuration(1000);
        objectAnimatorTranslate.start();
  1. 旋转
		ObjectAnimator objectAnimatorScale = ObjectAnimator.ofFloat(iv, "rotation", 0f, 360f);
        objectAnimatorScale.setDuration(1000);
        objectAnimatorScale.start();
  1. 组合
		AnimatorSet group = new AnimatorSet();
        ObjectAnimator objectAnimatorScaleX = ObjectAnimator.ofFloat(iv, "scaleX", 0f, 1f);
        ObjectAnimator objectAnimatorScaleY = ObjectAnimator.ofFloat(iv, "scaleY", 0f, 1f);
        ObjectAnimator objectAnimatorRotateX = ObjectAnimator.ofFloat(iv, "rotationX", 0f, 360f);
        ObjectAnimator objectAnimatorRotateY = ObjectAnimator.ofFloat(iv, "rotationY", 0f, 360f);
        ObjectAnimator objectAnimatorTranslate = ObjectAnimator.ofFloat(iv, "translationX", 0f, 500f);
        group.setDuration(2000);
        group.play(objectAnimatorScaleX).with(objectAnimatorScaleY)
                .before(objectAnimatorRotateX).before(objectAnimatorRotateY).after(objectAnimatorTranslate);
        group.start();
  1. ValueAnimator
		ValueAnimator valueAnimator = new ValueAnimator();
        valueAnimator.setDuration(3000);
        valueAnimator.setObjectValues(new PointF(0, 0));
        valueAnimator.setInterpolator(new LinearInterpolator());
        valueAnimator.setEvaluator(new TypeEvaluator<PointF>()
        {

            @Override
            public PointF evaluate(float fraction, PointF startValue,
                                   PointF endValue)
            {
                PointF point = new PointF();
                point.x = 200 * fraction * 3;
                point.y = 0.5f * 200 * (fraction * 3) * (fraction * 3);
                return point;
            }
        });
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
        {
            @Override
            public void onAnimationUpdate(ValueAnimator animation)
            {
                PointF point = (PointF) animation.getAnimatedValue();
                iv.setX(point.x);
                iv.setY(point.y);

            }
        });
        valueAnimator.start();
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值