Android 3.0 r1 Chinese API documentation (104) -- ViewTreeObserver

Source: Internet
Author: User

 

Preface

This chapter is about android. view. ViewTreeObserver. The version is Android 3.0 r1. The translation comes from "bear the brunt". Thanks again "bear the brunt "! I look forward to you join the Android API Chinese translation, contact me over140@gmail.com.

 

Statement

You are welcome to repost, but please keep the original source of the article :)

Blog Garden: http://www.cnblogs.com/

Android Chinese translation group: http://goo.gl/6vJQl

Body

I. Structure

Public final class ViewTreeObserver extends Object

Java. lang. Object

Android. view. ViewTreeObserver

 

Ii. Overview

The view tree observer (observer) used to register the listener is notified when the global event of the view tree is changed. This global event not only includes the layout of the entire tree, but also changes in the touch mode from the painting process. ViewTreeObserver cannot be instantiated by the application because it is provided by the view. getViewTreeObserver()To view more information.

 

Iii. Internal class

Interface ViewTreeObserver. OnGlobalFocusChangeListener

Interface Class of the callback function to be called when the focus status in a view tree changes

 

Interface ViewTreeObserver. OnGlobalLayoutListener

When the global layout of a view tree changes or the visual status of a view in the view tree changes, the interface class of the callback function to be called

 

Interface ViewTreeObserver. OnPreDrawListener

Interface Class of the callback function to be called when a view tree is to be drawn

 

Interface ViewTreeObserver. OnScrollChangedListener

Interface Class of the callback function to be called when some components in a view tree scroll

 

Interface ViewTreeObserver. OnTouchModeChangeListener

When the touch mode of a view tree changes, the interface class of the callback function to be called

 

Iv. Public Methods

Public voidAddOnGlobalFocusChangeListener(ViewTreeObserver. OnGlobalFocusChangeListener listener)

Register a callback function, which is called when the focus status in a view tree changes.

Parameters

Callback function to be added by listener

Exception

IllegalStateException if isAlive () returns false

Public voidAddOnGlobalLayoutListener(ViewTreeObserver. OnGlobalLayoutListener listener)

Register a callback function. This callback function is called when the global layout of a view tree changes or the visual status of a view in the view tree changes.

Parameters

Callback function to be added by listener

Exception

IllegalStateException if isAlive () returns false

Public voidAddOnPreDrawListener(ViewTreeObserver. OnPreDrawListener listener)

Register a callback function. This callback function is called when a view tree is to be drawn.

Parameters

Callback function to be added by listener

Exception

IllegalStateException if isAlive () returns false

Public voidAddOnScrollChangedListener(ViewTreeObserver. OnScrollChangedListener listener)

Register a callback function. This callback function is called when a view is rolled.

Parameters

Callback function to be added by listener

Exception

IllegalStateException if isAlive () returns false

Public voidAddOnTouchModeChangeListener(ViewTreeObserver. OnTouchModeChangeListener listener)

Register a callback function and call this callback function when the touch mode changes.

Parameters

Callback function to be added by listener

Exception

IllegalStateException if isAlive () returns false

 

Public final voidDispatchOnGlobalLayout()

When the entire layout changes, the corresponding registration listener is notified. If you force the view layout or a view that is not attached to a window or in the GONE status, it can be manually called

Public final booleanDispatchOnPreDraw()

When a view tree is to be drawn, the corresponding registration listener is notified. If the listener returns true, the painting will be canceled and rescheduled. If you force a view layout or a view hierarchy that is not attached to a window, or in a GONE state, it can be manually called

Return Value

If the current painting can be canceled and rescheduled, true is returned; otherwise, false is returned.

Public booleanIsAlive()

Indicates whether the current ViewTreeObserver is available (alive ). When the observer is unavailable, any method call (except this method) will throw an exception. If an application maintains a long reference with ViewTreeObserver, it always needs to detect the return value of this method before calling other methods.

Return Value

If this object is available, true is returned; otherwise, false is returned.

 

Public voidRemoveGlobalOnLayoutListener(ViewTreeObserver. OnGlobalLayoutListener victim)

Remove the previously registered global layout callback function.

Parameters

Callback function to be removed by victim

Exception

IllegalStateException if isAlive () returns false

 

Public voidRemoveOnGlobalFocusChangeListener(ViewTreeObserver. OnGlobalFocusChangeListener victim)

Remove the previously registered focus change callback function.

Parameters

Callback function to be removed by victim

Exception

IllegalStateException if isAlive () returns false

Public voidRemoveOnPreDrawListener(ViewTreeObserver. OnPreDrawListener victim)

Remove the previously registered pre-drawn callback function.

Parameters

Callback function to be removed by victim

Exception

IllegalStateException if isAlive () returns false

 

Public voidRemoveOnScrollChangedListener(ViewTreeObserver. OnScrollChangedListener victim)

Remove the previously registered rolling change callback function.

Parameters

Callback function to be removed by victim

Exception

IllegalStateException if isAlive () returns false

 

Public voidRemoveOnTouchModeChangeListener(ViewTreeObserver. OnTouchModeChangeListener victim)

Remove the previously registered touch mode change callback function

Parameters

Callback function to be removed by victim

Exception

IllegalStateException if isAlive () returns false

 

5. Supplement

Article Link

Android selection and text color

Related Article

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.