5

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?

David
  • 834
  • 1
  • 10
  • 27

3 Answers3

3

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

Community
  • 1
  • 1
spes
  • 484
  • 5
  • 16
0

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

toadzky
  • 3,806
  • 1
  • 15
  • 26
  • 1
    Neither of those are called in this particular instance. The activity handles configurations with onConfigurationChanged so the activity is not restarted. – David Oct 06 '12 at 02:32
  • hmmmm....why do you need the width and height of the webview? maybe there is another way to get the result you want. – toadzky Oct 07 '12 at 00:34
0

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

Archie
  • 161
  • 1
  • 8