在前面我们说过,将DecorView加载到Window中,是通过ViewRootImpl的setView方法进行的。ViewRootlImpl还有一个方法performTraversals,这个方法使得ViewTree开启了View的工作流程。
private void performTraversals(){
...
if(!mStopped){
int childWidthMeasureSpec = getRootMeasureSpec(mWidth,lp.width);
int childHeightMeasureSpec = getRootMeasureSpec(mHeight,lp.height);
performMeasure(lp,childWidthMeasureSpec ,childHeightMeasureSpec );
}
}
if(didLayout) {
performLayout(lp,desiredWindowWidth,desiredWindowHeight);
..
}
if(!cancelDraw && !newSureface) {
if(!skipDraw || mReportNextDraw) {
if(mPendingTransition != null && mPendingTransitions.size > 0) {
for(int i=0; i< mPendingTransitions.size;++i) {
mPendingTransitions.get(i).startChangingAimations();
}
mPendingTransitions.clear();
}
performDraw();
}
}
...
}
可以看到,这里主要执行了三个方法,分别是performMeasure,performLayout和performDraw,在其方法的内部又会分别调用View的measure,layout和draw方法。需要注意的是,在performMeasure方法中需要传入两个参数,分别是childWidthMeasure和childHeightMesureSpec。如果我们想了解这两个参数,就需要了解MeasureSpec。
performTraversals方法是AndroidUI渲染的关键步骤,它调用performMeasure、performLayout和performDraw来衡量、布局和绘制视图。在这过程中,measure方法使用childWidthMeasureSpec和childHeightMeasureSpec来确定View的大小,这两个参数基于MeasureSpec规则。同时,方法还涉及到了过渡动画的启动以及绘制的判断。
570

被折叠的 条评论
为什么被折叠?



