Android中属性动画7----ValueAnimator.ofObject的使用(抛物线运动)

本文介绍了如何将属性动画的运动轨迹从直线变为抛物线,模仿美团购物车动画。核心是修改BezierEvaluator中的公式为贝塞尔曲线二阶公式,并获取起点、终点和一个中间点的坐标来实现动画。提供了相关效果图、源码下载链接以及参考文章。
摘要由CSDN通过智能技术生成

本篇文章仅仅是把https://blog.csdn.net/zhaihaohao1/article/details/80941482的运动轨迹从直线变成了抛物线(就是美团购物车动画),其它都一样,代码上BezierEvaluator中的公式变了(变成了贝塞尔曲线二阶公式),坐标要起点,终点,和中间一个点的坐标。
开始讲:
效果图:
这里写图片描述
估值器中:BezierEvaluator 中

package com.zhh.myapplication.test2;

import android.animation.TypeEvaluator;
import android.graphics.Point;

/**
 *估值器
 */
public class BezierEvaluator implements TypeEvaluator<Point> {
   

    private Point controllPoint;

    public BezierEvaluator(Point controllPoint) {
        this.controllPoint = controllPoint;
    }

    @Override
    public Point evaluate(float t, Point startValue, Point endValue) {
//      贝塞尔曲线二阶公式
        int x = (int) ((1 - t) * (1 - t) * startValue.x + 2 * t * (1 - t) * controllPoint.x + t * t * endValue.x);
        int y = (int) ((1 - t) * (1 - t) * startValue.y + 2 * t * (1 - t) * controllPoint.y + t * t * endValue.y);
        return new Point(x, y);
    }


}

BallView自定义控件结合动画绘制

package com.zhh.myapplication.test2;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值