measurement of the process of View loading:rootview call measure() →onmeasure();
Measure() is the final method, suggesting that Android does not want developers to modify The measure framework, and developers can onmeasure methods.
Take a look at the measure code :
- Public ? final? void ? measure (intwidthmeasurespec,? int ? heightmeasurespec)? {??
- ???? if? ( (Mprivateflags?&? force_layout)? = =? force_layout?| |??
- ???????????? widthmeasurespec?! =?moldwidthmeasurespec?| |??
- ???????????? heightmeasurespec?! =?MOLDHEIGHTMEASURESPEC)? {??
- ???????? Mprivateflags?&=?~measured_dimension_set;??
- ???????? if? ( Viewdebug.trace_hierarchy)? {??
- ???????????? Viewdebug.trace (This,?) ViewDebug.HierarchyTraceType.ON_MEASURE);??
- ????????}??
- ???????? Onmeasure (Widthmeasurespec,?heightmeasurespec);??
- ???????? if? ( (Mprivateflags?&? Measured_dimension_set)?! =? Measured_dimension_set)? {??
- ???????????? throw? New ? IllegalStateException ("onmeasure () did?not?set?the"? ?
- ???????????????????? +? "? measured?dimension?by?calling"? ?
- ???????????????????? +? "? Setmeasureddimension ()"); ??
- ????????}??
- ???????? mprivateflags?| =? layout_required;??
- ????}??
- ???? Moldwidthmeasurespec?=?widthmeasurespec;??
- ???? Moldheightmeasurespec?=?heightmeasurespec;??
- }??
??
??
a display of an interface may involve many secondary measure, because a view often contains multiple sub-views, each of which requires a measure process. the Measurechildren () method is defined in viewgroupto measure the child view, and the following is the Measurechildren():
??
- protected ? voidmeasurechildren (intwidthmeasurespec,? int ? heightmeasurespec)? {??
- ???? final? int ? size?=?mchildrencount;??
- ???? final? View[]?children?=?mchildren;??
- ???? For ? ( int? i?=? 0;? i?<?size;? ++i)? {??
- ???????? final? View?child?=?children[i];??
- ???????? if? ( (Child.mviewflags?&? Visibility_mask)?! =? GONE)? {??
- ???????????? Measurechild (Child,?widthmeasurespec,?heightmeasurespec);??
- ????????}??
- ????}??
- }??
??
View Load Second step: onlayout, which is similar to measure, is called by the Rootview layout() →onlayout ().
??
??
Android Learning Note View (ii)