在Android Activity启动流程文章中已经介绍了,在activity的onResume之后,ViewRootImpl#setView(View view, WindowManager.LayoutParams attrs, ...)
,其中view就是DecorView,ViewRootImpl#setView中就会调用requestLayout
,然后调用scheduleTraversals
。这是首次调用,后续view的改动都会调用到scheduleTraversals
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| void scheduleTraversals() { if (!mTraversalScheduled) { mTraversalScheduled = true; mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier(); mChoreographer.postCallback( Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); notifyRendererOfFramePending(); pokeDrawLockIfNeeded(); } }
final TraversalRunnable mTraversalRunnable = new TraversalRunnable();
final class TraversalRunnable implements Runnable { @Override public void run() { doTraversal(); } }
void doTraversal() { if (mTraversalScheduled) { mTraversalScheduled = false; mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier);
if (mProfile) { Debug.startMethodTracing("ViewAncestor"); }
performTraversals();
if (mProfile) { Debug.stopMethodTracing(); mProfile = false; } } }
|