Custom Control (3): view rendering principle, view rendering
To customize the UI control, you must inherit the View class or View subclass and reload some methods in the View class. You do not have to reload them, but at least need to reload onDraw ().
| Category |
Method |
Description |
| Creation |
Constructors |
|
| OnFinishInflate () |
This method is called when View and all its sub-objects are imported from XML. |
| Layout |
OnMeasure (int, int) |
View will call this method to confirm the size of itself and all sub-objects |
| OnLayout (boolean, int, int) |
This method is called when the View needs to allocate the size and position of all sub-objects. |
| OnSizeChanged (int, int) |
This method is called when the View Size changes. |
| Drawing |
OnDraw (Canvas) |
This method is called when a View wants to draw its content |
| Event processing |
OnKeyDown (int, KeyEvent) |
This method is called when a new key event occurs. |
| OnKeyUp (int, KeyEvent) |
This method is called when a key release event occurs. |
| OnMotionEvent (MotionEvent) |
This method is called when an action event (such as touch) occurs. |
| Focus |
OnFocusChanged (boolean, int) |
This method is called when the View gets or loses focus. |
| Attaching |
OnAttachedToWindow () |
This method is called when a View is attached to a form. |
| OnDetachedFromWindow () |
This method is called when a View leaves its form. |
View Painting Process: onAttachedToWindow-> onMeasrue-> onSizeChanged-> onLayout-> onDraw
Draw View in Activity: Use setContentView () reference the root node of the input Hierarchy Tree-> Activity is activated and focused-> request the root node to calculate and draw the tree-> ViewGroup layout based on its own valid space and LayoutParams required by the child View child view, and call the Draw () method of the sub-view to Draw it.