About the Viewtreeobserver in Android

Source: Internet
Author: User
<span id="Label3"></p><span style="color: #ff0000;"><span style="color: #ff0000;">viewtreeobserver Structure</span></span><pre><pre><span style="color: #0000ff;">extends</span> <span style="color: #000000;">Objectjava.lang.Object ? Android.view.ViewTreeObserver</span></pre></pre><span style="color: #ff0000;"><span style="color: #ff0000;">Viewtreeobserver Overview</span></span><pre><pre><br><br><br><span style="color: #0000ff;">For</span></pre></pre><p><p>This observer listens to the view tree and listens for notifications when the view tree changes Globally. The global events referred to here include and are not limited to the following: layout changes throughout the view tree, start drawing views, Touch mode changes, and so On.</p></p><p><p>Viewtreeobserver is not instantiated by the application because it is provided by the view and is obtained through View.getviewtreeobserver (). Details need to see the getviewtreeobserver () method.</p></p><span style="color: #ff0000;"><span style="color: #ff0000;">Viewtreeobserver Inner class</span></span> <table style="width: 1360px;" border="0"> <tbody> <tr> <td>Interface</td> <td>Viewtreeobserver.ondrawlistener</td> <td><p>Interface definition for a callback to being invoked when the view tree was about to be drawn.</p><pre><span style="color: #008000;">When drawing in a view tree, the interface class of the callback function to be called</span></pre></td> </tr> <tr> <td>Interface</td> <td>Viewtreeobserver.onglobalfocuschangelistener</td> <td><p>Interface definition for a callback to being invoked when the focus state within the view tree Changes.</p><pre><span style="color: #008000;">The interface class of the callback function to invoke when the focus state in a view tree is changed</span></pre></td> </tr> <tr> <td>Interface</td> <td>Viewtreeobserver.ongloballayoutlistener</td> <td><p>Interface definition for a callback to being invoked when the global layout state or the visibility of views within the view Tree Changes.</p><pre><span style="color: #008000;">The interface class of the callback function to invoke when the global layout changes in one view tree or the visual state of a view in the view tree changes</span></pre></td> </tr> <tr> <td>Interface</td> <td>Viewtreeobserver.onpredrawlistener</td> <td><p>Interface definition for a callback to being invoked when the view tree was about to be drawn.</p><pre><span style="color: #008000;"><span style="color: #008000;">The interface class of the callback function to invoke when a view tree is about to be drawn</span></span></pre></td> </tr> <tr> <td>Interface</td> <td>Viewtreeobserver.onscrollchangedlistener</td> <td><p>Interface definition for a callback to being invoked when something in the view tree has been scrolled.</p><pre><span style="color: #008000;"><span style="color: #008000;">When some components in a view tree are scrolled, the interface class of the callback function to be called</span></span></pre></td> </tr> <tr> <td>Interface</td> <td>Viewtreeobserver.ontouchmodechangelistener</td> <td><p>Interface definition for a callback to being invoked when the touch mode Changes.</p><pre><span style="color: #008000;">When the touch mode of a view tree changes, the interface class of the callback function to be called</span></pre></td> </tr> </tbody> </table><span style="color: #ff0000;"><span style="color: #ff0000;">Viewtreeobserver Public Methods</span></span><p><p>1. Public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">addondrawlistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.ondrawlistener</span> listener)</span> </span> </span></p></p><pre><pre><span style="color: #008080;"><span style="color: #008000;">/** <span style="color: #008000;">Registers a callback function that is called when a view tree is Drawn. <span style="color: #008080;"><span style="color: #008000;">* Parameter Listener The callback function that will be added <span style="color: #008080;"><span style="color: #008000;">* Exception illegalstateexception if IsAlive () returns false<span style="color: #008080;"><span style="color: #008000;">*</span></span> /</span></span> </span></span> </span></span></span></pre></pre><p><p>2. Public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">addonglobalfocuschangelistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.onglobalfocuschangelistener </span>listener)</span> </span> </span></p></p><pre><pre><span style="color: #008080;"><span style="color: #008000;">/** <span style="color: #008000;">Registers a callback function that is called when the focus state in a view tree has Changed. <span style="color: #008080;"><span style="color: #008000;">* Parameter Listener The callback function that will be added <span style="color: #008080;"><span style="color: #008000;">* Exception illegalstateexception if IsAlive () returns false<span style="color: #008080;"><span style="color: #008000;">*</span></span> /</span></span> </span></span> </span></span></span></pre></pre><p><p>3. Public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">addongloballayoutlistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.ongloballayoutlistener</span> Listener)</span> </span> </span></p></p><pre><pre><span style="color: #008000;">/** <span style="color: #008000;">Registers a callback function that is called when the global layout changes in a view tree or when the visual state of a view in the View tree Changes. <span style="color: #008080;"><span style="color: #008000;">* Parameter Listener The callback function that will be added <span style="color: #008080;"><span style="color: #008000;">* Exception illegalstateexception if IsAlive () returns false<span style="color: #008080;"><span style="color: #008000;">*</span></span> /</span></span> </span></span> </span></span></pre></pre><p><p>4. Public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">addonpredrawlistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.onpredrawlistener</span> listener)</span> </span></span></p></p><pre><pre><span style="color: #008000;">/** <span style="color: #008000;">Registers a callback function that calls this callback function when a view tree is about to be drawn. <span style="color: #008080;"><span style="color: #008000;">* Parameter Listener The callback function that will be added <span style="color: #008080;"><span style="color: #008000;">* Exception illegalstateexception if IsAlive () returns false<span style="color: #008080;"><span style="color: #008000;">*</span></span> /</span></span> </span></span> </span></span></pre></pre><p><p>5. Public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">addonscrollchangedlistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.onscrollchangedlistener</span> Listener)</span> </span> </span></p></p><pre><pre><span style="color: #008080;"><span style="color: #008000;">/** <span style="color: #008000;">Registers a callback function that calls this callback function when a view is Scrolled. <span style="color: #008080;"><span style="color: #008000;">* Parameter Listener <span style="color: #008080;"><span style="color: #008000;"><span style="color: #008080;"><span style="color: #008000;">*/</span></span></span></span></span></span></span></span></span></pre></pre><p><p>6. Public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">addontouchmodechangelistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.ontouchmodechangelistener</span> Listener)</span> </span> </span></p></p><pre><pre><span style="color: #008000;">/** <span style="color: #008000;">Registers a callback function that calls this callback function when a touch mode change Occurs. <span style="color: #008080;"><span style="color: #008000;">* Parameter Listener The callback function that will be added <span style="color: #008080;"><span style="color: #008000;">* Exception illegalstateexception if IsAlive () returns false<span style="color: #008080;"><span style="color: #008000;">*</span></span> /</span></span> </span></span> </span></span></pre></pre><p><p>7. Public<span class="normal" style="background-color: #00ccff;">final void <span class="sympad">dispatchondraw <span class="normal">()</span> </span> </span></p></p><pre><pre><span style="color: #008000;">Inform the listener that the view drawing is started</span></pre></pre><p><p>8. Public<span class="normal" style="background-color: #00ccff;">final void <span class="sympad">dispatchongloballayout <span class="normal">()</span> </span> </span></p></p><pre><pre><span style="color: #008000;"><span style="color: #008000;">notifies the appropriate registration listener when the entire layout has Changed. If you force a view layout or a hierarchy of views that are not attached to a window or in the gone state, it can be called manually</span></span></pre></pre><p><p>9. Public<span class="normal" style="background-color: #00ccff;">Final Boolean <span class="sympad">dispatchonpredraw <span class="normal">()</span> </span> </span></p></p><pre><pre><span style="color: #008080;"><span style="color: #008000;">/** <span style="color: #008000;">notifies the appropriate registration listener when a view tree will be drawn. <strong>If the listener returns true, the drawing will be canceled and Re-scheduled. </strong> <span style="color: #008080;"><span style="color: #008000;">* return value <span style="color: #008080;"><span style="color: #008000;"></span></span> </span></span> </span> */</span></span></pre></pre><p><p>Ten. public<span class="normal" style="background-color: #00ccff;">boolean <span class="sympad">isAlive <span class="normal">()</span> </span> </span></p></p><pre><pre><span style="color: #008000;">/** <span style="color: #008000;">Indicates whether the current viewtreeobserver is available (alive). <strong>when Observer is not available, any call to the method (except this METHOD) throws an exception</strong> . If an application maintains and viewtreeobserver a long reference, it should always be necessary to detect the return value of the method before calling another Method. <span style="color: #008080;"><span style="color: #008000;">* return value but return true if this object is available, otherwise false <span style="color: #008080;"><span style="color: #008000;">*/</span></span></span></span></span></span></pre></pre><p><p>One. public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">removeglobalonlayoutlistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.ongloballayoutlistener</span> Victim)</span> </span> </span></p></p><pre><pre><span style="color: #008000;">/** <span style="color: #008000;">Removes the global layout callback function that was previously registered. <span style="color: #008080;"><span style="color: #008000;">* Parameter victim the callback function that will be removed <span style="color: #008080;"><span style="color: #008000;"><span style="color: #008080;"><span style="color: #008000;">*</span></span></span></span> </span></span> </span> /</span></pre></pre><p><p>Public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">removeondrawlistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.ondrawlistener</span> victim)</span> </span> </span></p></p><pre><pre><span style="color: #008000;">/** <span style="color: #008000;">Removes the previously registered view draw callback Function. <span style="color: #008080;"><span style="color: #008000;">* Parameter victim the callback function that will be removed <span style="color: #008080;"><span style="color: #008000;"><span style="color: #008080;"><span style="color: #008000;">*</span></span></span></span> </span></span> </span> /</span></pre></pre><p><p>Public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">removeonglobalfocuschangelistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.onglobalfocuschangelistener </span>victim)</span> </span> </span></p></p><pre><pre><span style="color: #008000;">/** <span style="color: #008000;">Removes the previously registered focus change callback Function. <span style="color: #008080;"><span style="color: #008000;">* Parameter victim the callback function that will be removed <span style="color: #008080;"><span style="color: #008000;"><span style="color: #008080;"><span style="color: #008000;">*</span></span></span></span> </span></span> </span> /</span></pre></pre><p><p>Public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">removeonpredrawlistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.onpredrawlistener</span> victim)</span> </span></span></p></p><pre><pre><span style="color: #008000;">/** <span style="color: #008000;">removes Pre-drawn callback functions that have been previously registered. <span style="color: #008080;"><span style="color: #008000;">* Parameter victim the callback function that will be removed <span style="color: #008080;"><span style="color: #008000;"><span style="color: #008080;"><span style="color: #008000;">*</span></span></span></span> </span></span> </span> /</span></pre></pre><p><p>. public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">removeonscrollchangedlistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.onscrollchangedlistener</span> Victim)</span> </span> </span></p></p><pre><pre><span style="color: #008000;">/** <span style="color: #008000;">Removes the previously registered scroll change callback Function. <span style="color: #008080;"><span style="color: #008000;">* Parameter victim the callback function that will be removed <span style="color: #008080;"><span style="color: #008000;"><span style="color: #008080;"><span style="color: #008000;">*</span></span></span></span> </span></span> </span> /</span></pre></pre><p><p>. public<span class="normal" style="background-color: #00ccff;">void <span class="sympad">removeontouchmodechangelistener <span class="normal">(<span style="background-color: #00ccff;">viewtreeobserver.ontouchmodechangelistener </span>victim)</span> </span> </span></p></p><pre><pre><span style="color: #008080;"><span style="color: #008000;">/** <span style="color: #008000;">Remove the previously registered touch mode change callback function <span style="color: #008080;"><span style="color: #008000;">* parameter victim the callback function that will be removed <span style="color: #008080;"><span style="color: #008000;">* Exception illegalstateexception if IsAlive () returns false */<span style="color: #008080;"><span style="color: #008000;"></span></span> </span></span></span></span></span></span></span></pre></pre><p><p></p></p><p><p>About the Viewtreeobserver in Android</p></p></span>

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.