Custom Control (3): view rendering principle, view rendering

Source: Internet
Author: User

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.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.