View的绘制流程的绘制流程
View的绘制流程主要包括measure,layout,draw三大流程,measure用来确定view的测量宽/高,layout用来确定view的最终
宽/高和四个顶点的位置,而draw则将View绘制到屏幕上
Measure
如果只是一个原始的View,那么通过meaure方法就完成了其测量过程,如果是一个ViewGroup,除了完成自己的测量过程
外,还会遍历去调用所有子View的measure方法,各个子元素再去递归调用这个流程
view的measure过程由measure方法来完成,measure方法是一个final方法,这意味着子类不能重写此方法,在View的
measure方法中回去调用view的onMeasure方法
onMeasure方法如下(直接继承原始View)
/**
*
* 测量视图及其内容以确定测量的宽度和测量的高度,这个方法由measure方法调用,并且应该被子类重写,以
* 准确和有效的测量其内容
* Measure the view and its content to determine the measured width and the
* measured height. This method is invoked by {@link #measure(int, int)} and
* should be overridden by subclasses to provide accurate and efficient
* measurement of their contents.
*
*
*
* 当子类重写了此方法,则必须调用setMeasuredDimension方法来存储view的测量宽/高,如果不这样做将会触发由
*measure方法抛出的异常throw new IllegalStateException("View with id " + getId() + ": "
+ getClass().getName() + "#onMeasure() did not set the"
+ " measured dimension by calling"
+ " setMeasuredDimension()");
* CONTRACT: When overriding this method, you
* must call {@link #setMeasuredDimension(int, int)} to store the
* measured width and height of this view. Failure to do so will trigger an
* IllegalStateException, thrown by