关于ObjectAnimator

基本使用

java 复制代码
    ObjectAnimator animator = ObjectAnimator.ofFloat(view,"alpha",1,0,1);
    animator.start();

关键点在于第二个参数:String propertyName 如果需要使用这个参数对应的效果,需要操作的view中有对应的set属性方法(set 函数的命名必须采用骆驼拼写法)。 例如:alpha 对应 setAlpha()方法

引用自《Android自定义控件开发入门与实战》

所以ValueAnimator 一般在回调中操作,而ObjectAnimator方便在自定义view中调用相应的方法。

关于ofObject()的使用

ofObject()可以帮助我们处理的值不限于int或者float,我们可以传自定义的值进行处理,如对象。

使用实例:

java 复制代码
ObjectAnimator animator = ObjectAnimator.ofObject(view,"jump",new JumpEvaluator(),new Point(0,0),new Point(30,30));
animator.setDuration(299);
animator.start();
java 复制代码
public class JumpEvaluator implements TypeEvalutor<Point>{
    private Point point = new Point();
   
    @Override
    public Point evaluate(float fraction, Point startValue, Point endValue) { 
        //自己的逻辑
        //point.x = (int)(startValue.x + fraction *(endValue.x - startValue.x));
        //if (fraction*2<=1){ 
        //    point.y = (int)(startValue.y + fraction*2*(endValue.y - startValue.y));
        // }else { 
        //    point.y = endValue.y; 
        //} 
    return point;
}

注意

对于ofFloat(),ofInt()最后一个可变参数,如果只传一个值,因为对应的get方法,而float,int 对应默认值为0,所以系统会报警告但不至于崩溃,而ofObject()对应的属性,没有默认的get方法,所以单个参数会崩溃

其他

void setRepeatCount(int value) //设置循环次数,设置为 INFINITE 表示无限循环

相关推荐
TimeFine2 小时前
AI 编程工作流的设计:从人工判断到 AI裁判
android·ai编程
阿杰m2 小时前
Android源码第四章:Android 系统启动——App 的第一行代码从哪来?
android
疯华整猫6 小时前
混淆起初根本不是为了防破解:我用 Trae 把 Android 混淆这二十来年重跑了一遍
android·人工智能·计算机视觉
Carson带你学Android7 小时前
AI时代,你的 App 会被 Agent 这三种方式调用
android·ai编程
恋猫de小郭8 小时前
Flutter 下 AOT 一个你怎么都想不出来的 Bug ,JIT 正常的计算,在 AOT 居然算错了
android·前端·flutter
好的佩奇1 天前
Dart 之扩展方法
android·flutter·dart
三少爷的鞋1 天前
换个思路理解:非阻塞挂起
android
好的佩奇1 天前
蓝牙之经典蓝牙
android·flutter·蓝牙
传奇开心果编程1 天前
【Flutter踩坑排雷】第19课:路由硬编码坑|字符串路由书写错误,页面跳转失败排查
android·flutter·ios·移动开发·跨平台·ui框架·声明式ui
微小的鱼1 天前
Linux的渲染与显示系统链路
android·java·linux