Android Getting Calculated View Dimensions edit

Getting Calculated View Dimensions


Note that a ViewTreeObserver instance associated with a View instance can become invalid while that View is still alive. From the View.getViewTreeObserver javadocs:

// The returned ViewTreeObserver observer is not guaranteed to remain
// valid for the lifetime of this View. If the caller of this method keeps
// a long-lived reference to ViewTreeObserver, it should always check for
// the return value of {@link ViewTreeObserver#isAlive()}.

Thus, if you have previously added a listener to a ViewTreeObserver instance and now wish to remove it, it is easiest to call getViewTreeObserver on the corresponding View instance again to receive a fresh ViewTreeObserver instance. (Checking isAlive on an existing instance is more work for little benefit; if the ViewTreeObserver is no longer alive, you’ll be fetching that fresh reference anyway!)

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
12 Getting Calculated View Dimensions
64 Menu
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close