自定义View - 17.draw()源码分析

performTraversals{

    //绘制
    performDraw();
}

private void performDraw() {
    draw(fullRedrawNeeded);
}


private void draw(boolean fullRedrawNeeded) {
    if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, scalingRequired, dirty)) {
                    return;
    }
}

private boolean drawSoftware(){
    mView.draw(canvas);
}
public void draw(Canvas canvas) {
    //绘制背景
    drawBackground(canvas);

    //绘制自己
   if (!dirtyOpaque) onDraw(canvas);

    //绘制子View
   dispatchDraw(canvas);

   //绘制前景,scrollbars
   onDrawForeground(canvas);
}

对于ViewGroup首先绘制自己的背景,for循环绘制子View调用子View的draw()方法.
对于view绘制自己的背景,绘制自己的背景和自己显示的内容.

你可能感兴趣的:(自定义View - 17.draw()源码分析)