属性动画源码分析

1. 属性动画流程图如下


图片.png

2. 属性动画源码


 // prefix = set,propertyName = scaleX
static String getMethodName(String prefix, String propertyName) {  
        if (propertyName == null || propertyName.length() == 0) {
            // shouldn't get here
            return prefix;
        }

        //  把 propertyName 第一个字母变成大写  S
        char firstLetter = Character.toUpperCase(propertyName.charAt(0));
        // 截取 propertyName 从第一个字母到最后一个字母  caleX
        String theRest = propertyName.substring(1);
        // 返回方法名 = set+S+caleX = setScaleX
        return prefix + firstLetter + theRest;
    }
  • 分析属性动画
        ImageView imageView = null ;
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(imageView , "scaleX" , 1f) ;
        objectAnimator.setDuration(3000) ;
        objectAnimator.start();

属性动画就是:只要一调用 imageview.start()方法,会不断的调用 image.setScaleX()方法

  • mSetter.invoke(target,mTmpValueArray);
    属性动画说白了就是,android的 jni层 每隔 16ms 不断的回调 ObjectAnimator 的 doAnimationFrame()方法,最终其实就是通过反射方法invoke() 去调用 view.setXxx()方法:
    比如:view.setScaleX(1f)、view.setTranslationY(0.5f);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容