Android View/viewgroup life cycle-Custom View

Source: Internet
Author: User

Start with the construction method, and then click Execute

Onattachtowindow-->onmeasure-->onsizechanged-->onlayout--> onmeasure-->onlayout-->ondraw- ->ondetachedfromwindow

The method invocation process in Title view and ViewGroup is summarized as follows:

1. First, the Activity oncreate and initializes the view

2. Then, after the Activity Onresume calls the view's Onattachedtowindow, it often does the initialization work in the Onattachedtowindow method, such as registering some broadcasts, starting the animation, etc...

3. Next, if the background is set, call OnDraw, and then call Dispatchdraw if it is viewgroup.

Description: Dispatchdraw () is mostly distributed to sub-assemblies for drawing, and we typically override the OnDraw () method when customizing components. It is noteworthy that the ViewGroup container component is drawn, and when it does not have a background, it calls the Dispatchdraw () method directly, bypassing the draw () method, invoking the draw () method when it has a background, and draw () The method contains a call to the Dispatchdraw () method. So the Dispatchdraw () method instead of the OnDraw () method is often overridden to draw on ViewGroup, or a drawable is customized, and the draw (Canvas C) and Getintrinsicwidth () are rewritten. , Getintrinsicheight () method, and then set as background.

4. Finally, when you click the fallback button, Activity OnDestroy after the call Ondetachedfromwindow, then we do some finishing work in this method, such as: Cancel broadcast registration, stop animation and so on.

Description: OnDraw and Dispatchdraw will probably be called multiple times due to setvisible or onresume, Onattachedtowindow and Ondetachedfromwindow are called only once during the creation and destruction of the view.

5. Onmeasure and OnLayout are also called multiple times during creation.

For more knowledge, you can see the user link http://www.2cto.com/kf/201409/331256.html

http://blog.csdn.net/stevenhu_223/article/details/18360397 (by the way, see the use of weakpeference)

Note: The onfinishinflate call, when all the child controls in view are mapped to XML, is triggered, that is, Onfinishinflate-->onattachtowindow ...

Android View/viewgroup life cycle-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.