屬性動畫源碼分析

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 第一個(gè)字母變成大寫  S
        char firstLetter = Character.toUpperCase(propertyName.charAt(0));
        // 截取 propertyName 從第一個(gè)字母到最后一個(gè)字母  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();

屬性動畫就是:只要一調(diào)用 imageview.start()方法,會不斷的調(diào)用 image.setScaleX()方法

  • mSetter.invoke(target,mTmpValueArray);
    屬性動畫說白了就是,android的 jni層 每隔 16ms 不斷的回調(diào) ObjectAnimator 的 doAnimationFrame()方法,最終其實(shí)就是通過反射方法invoke() 去調(diào)用 view.setXxx()方法:
    比如:view.setScaleX(1f)、view.setTranslationY(0.5f);
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容