Activity启动流程:
ActivityThread
1、ActivityThread中调用了handleLaunchActivity()->performLaunchActivity() 通过反射创建Activity调用callActivityOnCreate(Activity activity, Bundle icicle,
PersistableBundle persistentState)->activity.performCreate()->
image.png
调用了onCreate()方法->onCreate调用setContentView->ensureSubDecor->createSubDecor->PhoneWindow中的getDecorView->installDecor->generateDecor最后这个方法中创建了DecorView;
onCreate中并没有调用View的Measure方法所以无法在onCreate中获取控件的宽高
2、onResume->ActivityThread中调用了
handleResumeActivity()
->先调用performResumeActivity()->performResume()->activity.performResume()->callActivityOnResume(this)->
image.png并没有为View测量所以在onResume也无法获取控件的宽高,同理在onStart也无法获取控件宽高
->WindowManager->addView()将DecorView添加进去 之后才开始measure layout draw的方法
View绘制流程
ViewRootImpl
ViewGroup默认不走onDraw 设置背景后会走onDraw
测量:setView(View LayoutParams View)
->requestLayout()
->scheduleTraversals()
->TraversalRunnable()的run方法
->doTraversal
->performTraversals
->performMeasure
->View.measure
->onMeasure
->performDraw
->draw(boolean fullRedrawNeeded)
->drawSoftware
->draw(canvas)
->接着就是
//draw 背景
drawBackground(canvas);
// Step 3, draw the content draw自己
onDraw(canvas);
// Step 4, draw the children draw子View
dispatchDraw(canvas);
网友评论