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)