Android Learning Note View (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.