Number of Onmeasure calls
When the activity gets the focus, it needs to draw the layout. The Android framework handles the drawing process, but the activity must provide the root node of its layout tree.
The drawing process starts from the root node of the layout. this process involves measuring and drawing the layout tree . The drawing process is handled by traversing the tree and rendering each view that intersects the drawing area. Next,ViewGroup's job is to request that each of its child views be drawn (using the Draw () method), while the job of view is to draw itself. Since this tree is traversed sequentially, this means that the parent view is drawn before the child view, and the siblings are drawn according to the order in which they appear in the tree.
The framework does not draw a view object that is not in the drawing area, and it also provides you with the ability to draw a view in the background. by calling invalidate (), you can force the drawing of the view.
There are two procedures for drawing a layout: The measure process and the layout process. The measurement process is achieved through measure (Int,int), which is a top-down traversal process. During traversal, each view passes the dimension description into the tree below. At the end of the measurement process, each view stores its measured values. The second process is triggered by layout (Int,int,int,int) and is a top-down process. In this process, the responsibility of the parent view is to use the dimensions calculated by the measurement process to place all its child views.
When the measure () of a View object returns, its Getmeasuredwidth () and Getmeasuredheight () methods are bound to have values, and all of its descendant views are the same. The width and height after the view object is measured must be constrained by the View object's parent view. This guarantees that at the end of the measurement process, all parent views will accept the measured values of their child views. The parent view may call more than once on its child view measure (Int,int) method. For example, the parent view can use unspecified dimensions to measure each of its sub-views once to figure out how large they need to be, if all of these sub-views are not limited in size and are too large or too small, Then it will call measure () again with an exact value (that is, if the sub-view is not satisfied with the size of the area they are getting, then the parent view will intervene and set the second measurement rule).
In order to initiate a layout, you need to call Requestlayout (). This method is called by the view itself when the view is sure that the area assigned to it is no longer being adjusted.
The measurement process uses two classes to pass the dimensions. The View object uses the Viewgroup.layoutparams class to tell the parent view how they want to be measured and placed. The basic Viewgroup.layoutparams class only describes how wide and high the view needs to be. It can be specified in any one of the following sizes:
1. Exact numbers
2.match_parent, meaning that this view needs to be as large as its parent view (minus padding)
3.wrap_content means that the view needs to be large enough to fit the contents (plus padding)
There are viewgroup.layoutparams subclasses for different viewgroup subclasses. For example, Relativelayout has its own viewgroup.layoutparams subclass, which contains the ability to center a child view horizontally and vertically.
Portal: "Android-Measurespec" http://www.cnblogs.com/yydcdut/p/4170629.html
Onmeasure and OnLayout
When inheriting the ViewGroup class, you need to rewrite two methods, namely Onmeasure and OnLayout.
1, call the Setmeasureddimension method in method Onmeasure
void setmeasureddimension (intint measuredheight)
In onmeasure (int, int), call setmeasureddimension (int width, int height) to store the measured width and height values.
2, call your child's Measure method in method onmeasure
void measure (intint heightmeasurespec)
This method is used to measure the size of the view. The parent view uses the width parameter and the height parameter to provide constraint information. In fact, the measurement of the view is done in the onmeasure (int, int) method. Therefore, only the onmeasure (int, int) method can and must be overridden. Parameter Widthmeasurespec provides a specification of the horizontal space of the view, and the parameter Heightmeasurespec provides a specification of the vertical space of the view.
3, parsing onmeasure (int, int) method
void onmeasure (intint heightmeasurespec)
Measure the view and its contents to determine the width and height of the view. This method is called in measure (int, int) and must be rewritten to accurately and effectively measure the contents of the view.
The basic measurement data for a view defaults to its background size, unless a larger size is allowed. The child view must override Onmeasure (int, int) to provide a more accurate measurement of its contents. If overridden, the subclass ensures that the measured height and width are at least the minimum height and width of the view (obtained by Getsuggestedminimumheight () and Getsuggestedminimumwidth ().
4, parsing onlayout (boolean, int, int, int, int) method
void OnLayout (booleanint int int int b)
Call scenario: Called when a view is set to its child's size and position. Child view, including children, must override the OnLayout (boolean, int, int, int, int) methods, and invoke the respective layout (int, int, int, int) methods.
Parameter description: The parameter changed indicates that the view has a new dimension or position; The parameter L represents the left position relative to the parent view; the parameter T represents the top position relative to the parent view; The parameter r represents the right position relative to the parent view. The parameter B represents the bottom position relative to the parent view.
I'm the dividing line of the king of the Land Tiger.
Android--Onmeasure