Develop custom View

Source: Internet
Author: User

When developers intend to derive their own UI components, they first define a subclass that inherits the view base class, and then override one or more methods of the View class. The methods that can be rewritten by users are as follows:
Constructor: the rewritable constructor is the most basic method for customizing views. When Java code creates a view instance or loads and constructs the interface according to the XML layout file, the constructor is called.
Onfinishinflate (): This is a callback method. When an application loads the component from an XML layout file and uses it to build the interface, this method is called back.
Onmeasure (INT, INT): Call this method to check the size of the view component and all its child components.
Onlayout (Boolean, Int, INT): This method is called back when the component needs to be assigned its sub-component location and size.
Onsizechanged (INT, Int, Int, INT): This method is called back when the component size is changed.
Ondraw (cancas): calls back this method when the component is about to draw its content.
Onkeydown (INT, keyevent): This method is triggered when a key is pressed.
Onkeyup (INT, keyevent): This method is triggered when a key is released.
Ontrackballevent (motionevent): This method is triggered when a trackball event occurs.
Ontouchevent (motionevent): This method is triggered when a touch screen event occurs.
Onwindowfocuschanged (Boolean): This method is triggered when the component gets or loses focus.
Ondetachedfromwindow (): This method is triggered when the component is detached from a window.
Onwindowvisibilitychanged (INT): This method is triggered when the visibility of the window containing this component changes.
To develop a custom view, you do not need to overwrite all the methods listed above. Instead, you can rewrite some of the above methods as needed.

Develop custom View

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.