Android onmeasure (Widthspec, Heightspec)

Source: Internet
Author: User


In each view, there is a way to measure the size of the control onmeasure (int widthmeasurespec, int heightmeasurespec), which is used to initialize the area occupied by the control:

Excerpt from Slidingdrawer.java, for reference only onmeasure (int widthmeasurespec, int heightmeasurespec) method

@Overrideprotected voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) {        //the Onmeasure method passes the two parameters Widthmeasurespec, Heightmeasurespec, which are in DP or dip            intWidthspecmode = Measurespec.getmode (Widthmeasurespec);//Here the unit is determined by DP or dip, with or other unit type        intWidthspecsize = Measurespec.getsize (Widthmeasurespec);//convert units to PX        intHeightspecmode =Measurespec.getmode (HEIGHTMEASURESPEC); intHeightspecsize =measurespec.getsize (HEIGHTMEASURESPEC); if(Widthspecmode = = Measurespec.unspecified | | heightspecmode = =measurespec.unspecified) {Throw NewRuntimeException ("Slidingdrawer cannot has UNSPECIFIED dimensions"); }        //        FinalView handle =Mhandle;        Measurechild (handle, Widthmeasurespec, Heightmeasurespec); if(mvertical) {intHeight = heightspecsize-handle.getmeasuredheight ()-Mtopoffset; Mcontent.measure (Measurespec.makemeasurespec (Widthspecsize, measurespec.exactly), MeasureSpec.makeMeasu        Respec (height, measurespec.exactly)); } Else {            intwidth = widthspecsize-handle.getmeasuredwidth ()-Mtopoffset; Mcontent.measure (Measurespec.makemeasurespec (width, measurespec.exactly), Measurespec.makemeasurespec (H        Eightspecsize, measurespec.exactly)); }        //the size of the parent control is finally drawnsetmeasureddimension (widthspecsize, heightspecsize); //The super.onmeasure (Widthmeasurespec, Heightmeasurespec) prototype is written in the following way://setmeasureddimension (Getdefaultsize (Getsuggestedminimumwidth (), Widthmeasurespec),//getdefaultsize (Getsuggestedminimumheight (), Heightmeasurespec));}


Android onmeasure (Widthspec, Heightspec)

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.