View绘制流程
2018-09-28 本文已影响0人
_Rice_
View绘制流程函数调用链(简化版)

参考:http://www.gcssloop.com/customview/CustomViewProcess
1、measure
MeasureSpec

组成:测量规格(MeasureSpec) = 测量模式(mode) + 测量大小(size)

其中,测量模式(Mode)的类型有3种:UNSPECIFIED、EXACTLY 和
AT_MOST。具体如下:

子view的大小由父view的MeasureSpec值 和 子view的LayoutParams属性 共同决定

其中的规律总结:(以子View为标准,横向观察)

现在,分别讨论两种measure过程:
①View的measure:

②ViewGroup的measure:

参考:https://www.jianshu.com/p/1dab927b2f36
2、layout
流程:view依次调用layout()过程中会调用setFrame()设置view本身的四个顶点位置,接着调用onLayout来确定其坐标,该方法是控方法,因为不同的viewGroup对其子View的布局是不同的。
layout过程根据View的类型分为2种情况:


参考:https://www.jianshu.com/p/158736a2549d
3、draw
draw过程根据View的类型分为2种情况:

