android 属性动画源码分析

https://blog.csdn.net/lmj623565791/article/details/42056859

 

onAnimationUpdate:41, MainActivity$1$1 (com.example.ronnie.test)
animateValue:1547, ValueAnimator (android.animation)
animateBasedOnTime:1339, ValueAnimator (android.animation)
doAnimationFrame:1471, ValueAnimator (android.animation)
doAnimationFrame:146, AnimationHandler (android.animation)
access$100:37, AnimationHandler (android.animation)
doFrame:54, AnimationHandler$1 (android.animation)
run:947, Choreographer$CallbackRecord (android.view)
doCallbacks:761, Choreographer (android.view)
doFrame:693, Choreographer (android.view)
run:935, Choreographer$FrameDisplayEventReceiver (android.view)
handleCallback:873, Handler (android.os)
dispatchMessage:99, Handler (android.os)
loop:193, Looper (android.os)
main:6669, ActivityThread (android.app)
invoke:-1, Method (java.lang.reflect)
run:493, RuntimeInit$MethodAndArgsCaller (com.android.internal.os)
main:858, ZygoteInit (com.android.internal.os)

属性动画每次更新的堆栈如上, 从堆栈可以看出,都是用Choreographer注册FrameDisplayEventReceiver监听屏幕的刷新时机,然后回掉给AnimationHandler,再传递给Animator去根据当前的时间计算value,这是需要使用差值器和估值器去计算

 

下面的堆栈的tween动画的刷新堆栈

applyTransformation:68, AlphaAnimation (android.view.animation)
getTransformation:906, Animation (android.view.animation)
getTransformation:980, Animation (android.view.animation)
applyLegacyAnimation:19757, View (android.view)
draw:19873, View (android.view)
drawChild:4333, ViewGroup (android.view)
dispatchDraw:4112, ViewGroup (android.view)
dispatchDraw:2023, ConstraintLayout (android.support.constraint)
updateDisplayListIfDirty:19073, View (android.view)
recreateChildDisplayList:4317, ViewGroup (android.view)
dispatchGetDisplayList:4290, ViewGroup (android.view)
updateDisplayListIfDirty:19042, View (android.view)
recreateChildDisplayList:4317, ViewGroup (android.view)
dispatchGetDisplayList:4290, ViewGroup (android.view)
updateDisplayListIfDirty:19042, View (android.view)
recreateChildDisplayList:4317, ViewGroup (android.view)
dispatchGetDisplayList:4290, ViewGroup (android.view)
updateDisplayListIfDirty:19042, View (android.view)
recreateChildDisplayList:4317, ViewGroup (android.view)
dispatchGetDisplayList:4290, ViewGroup (android.view)
updateDisplayListIfDirty:19042, View (android.view)
recreateChildDisplayList:4317, ViewGroup (android.view)
dispatchGetDisplayList:4290, ViewGroup (android.view)
updateDisplayListIfDirty:19042, View (android.view)
updateViewTreeDisplayList:686, ThreadedRenderer (android.view)
updateRootDisplayList:692, ThreadedRenderer (android.view)
draw:801, ThreadedRenderer (android.view)
draw:3311, ViewRootImpl (android.view)
performDraw:3115, ViewRootImpl (android.view)
performTraversals:2484, ViewRootImpl (android.view)
doTraversal:1460, ViewRootImpl (android.view)
run:7183, ViewRootImpl$TraversalRunnable (android.view)
run:949, Choreographer$CallbackRecord (android.view)
doCallbacks:761, Choreographer (android.view)
doFrame:696, Choreographer (android.view)
run:935, Choreographer$FrameDisplayEventReceiver (android.view)
handleCallback:873, Handler (android.os)
dispatchMessage:99, Handler (android.os)
loop:193, Looper (android.os)
main:6669, ActivityThread (android.app)
invoke:-1, Method (java.lang.reflect)
run:493, RuntimeInit$MethodAndArgsCaller (com.android.internal.os)
main:858, ZygoteInit (com.android.internal.os)

 

tween动画和属性动画的实现原理完全不同,

tween动画是在刷新的过程中,viewgroup在dispatchDraw的过程中,如果当前view的animation存在,通过执行applyTransformation 来实现视觉上的动画

属性动画是通过监听vsync信号,由chroegraphor回掉来通过valueanimator计算当前的时间以及value来实现动画.

你可能感兴趣的:(android)