Layout
Layout is a two-pass process: transfer skipping and layout. An intermediate pass is implemented in measure(int, int) and is a reverse look at the view tree. Each view pushes the size specifications to the tree during the recursion. At the end of the passage of the measure, each species stores its measurements. The second pass happens in layout(int, int, int, int) , and also from top to bottom. During this passage, each parent is responsible for placing all their children using the dimensions calculated in the measure passage.
When the view () method returns a value, its getMeasuredWidth() and getMeasuredHeight() values must be set along with the values for all of these view children. Presented measured widths and measured heights should take into account the restrictions imposed by the parents of the gaze. This ensures that at the end of the event, all parents take all the measurements of their children. A parent view can repeatedly call a measure () on its children. For example, a parent can measure each child once with indefinite measurements to find out how big they are, and then call measure () again with real numbers if the sum of all child unlimited sizes is too large or too small.
Skipping measures uses two classes to pass measurements. The View.MeasureSpec class View.MeasureSpec used by views to tell parents how they want to be measured and positioned. The base class LayoutParams simply describes how large the view should be both in width and in height. For each dimension, he can indicate one of:
- exact number
- MATCH_PARENT, which means that the view wants to be as large as its parent (minus padding)
- WRAP_CONTENT, which means the view wants to be large enough to add its contents (plus an addition).
There are subclasses of LayoutParams for different subclasses of ViewGroup. For example, AbsoluteLayout has its own subclass of LayoutParams, which adds the values of X and Y.
MeasureSpecs are used to push tree requirements from parent to child. A MeasureSpec can be in one of three modes:
- UNSPECIFIED: Used by the parent to determine the desired size of the baby species. For example, LinearLayout can call measure () on its child with a height set to UNSPECIFIED and a width EXACTLY 240 to find out how tall a child should be given a width of 240 pixels.
- EXACTLY: this is used by the parent to impose the exact size on the child. The child must use this size and ensure that all of his descendants comply with this size.
- AT_MOST: used by the parent to overlay the maximum size on the child. The child must guarantee that he and all his descendants will be consistent with this size.
To start linking, call requestLayout() . This method is usually invoked by the idea of it when it considers that it can no longer match its current boundaries.
samosaris
source share