The layout of Android consists of two phases: Measure () and requestlayout (). One measurespec encapsulates the layout requirements for the parent layout to pass to the Child layout. Each measurespec represents a width or height requirement. A measurespec contains a size and mode. Three Modes of measurespec: Unspecified: the parent layout does not limit the child layout, and the Child layout can be any size. Exactly: Specifies the exact size of the parent layout. No matter how large the sub-layout is, it must be limited to this limit. At_most: You can select any size based on your size. @ Override protected void onmeasure (INT widthmeasurespec, int percent) {int measuredheight = measureheight (percent); int measuredwidth = measurewidth (widthmeasurespec); Measures (measuredheight, measuredwidth ); // final displaymetrics metrics = getresources (). getdisplaymetrics (); // setmeasureddimension (mbitmap. getscaledwidth (metrics), mbitmap. getscaledheight (metrics);} private int measureheight (INT measurespec) {int specmode = measurespec. getmode (measurespec); int specsize = measurespec. getsize (measurespec); int result = 500; If (specmode = measurespec. at_most) {result = specsize;} else if (specmode = measurespec. exactly) {result = specsize;} return result;} private int measurewidth (INT measurespec) {int specmode = measurespec. getmode (measurespec); int specsize = measurespec. getsize (measurespec); int result = 500; If (specmode = measurespec. at_most) {result = specsize;} else if (specmode = measurespec. exactly) {result = specsize;} return result;} creationconstructors Onfinishinflate () When view and all its sub-objects are imported from XML, call this method layoutonmeasure (INT, INT) View will call this method to confirm the onlayout (Boolean, Int, INT) Size of itself and all sub-objects) This method onsizechanged (INT, Int, Int, INT) is called when the view needs to allocate the size and position to all sub-objects) When the View Size changes, call this method drawingondraw (canvas) When a view wants to draw its content, call this method event processingonkeydown (INT, keyevent) This method is called onkeyup (INT, keyevent) when a new key event occurs) When a key release event occurs, call this method onmotionevent (motionevent) When an Action event (such as touch) occurs, call this method focusonfocuschanged (Boolean, INT) Call attachingonattachedtowindow () when the view gets or loses the focus () When a view is appended to a form, this method ondetachedfromwindow () is called () When a view leaves its form, call this method. When you add a visible view to an activty and run this activty, generally, Android triggers view-related events in the following order: onattachedtowindowonmeasureonsizechangedonlayoutondraw
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