David
David

Reputation: 874

Android: Width and Height of View After Orientation Change

I need to get the width and height of a WebView and pass them in the query string of the URL I am loading in the WebView. I have found a way to do this in onResume(). Since the width and height are not calculated at this point, I post a Runnable to the WebView to be queued for after the UI loads.

Here's my problem: when the orientation changes, I am handling it in onConfigurationChanged. When I try to post a Runnable in onConfigurationChanged to the WebView, the WebView's width and height end up being the old orientation's width and height. At what point can I intercept the new width and height after orientation change?

Upvotes: 5

Views: 4369

Answers (3)

Archie
Archie

Reputation: 161

This only works with the parent view or getRootView() it returns the same ht and wd for the child view.

Upvotes: 0

spes
spes

Reputation: 484

Use a ViewTreeObserver, for an example check out this answer: https://stackoverflow.com/a/8245468/757073

Upvotes: 3

toadzky
toadzky

Reputation: 3846

Try in onPostResume. This gets called after onResume, which is supposed to be called when it gets ready to put it on screen.

Upvotes: 0

Related Questions