Android: view width and height after changing orientation

I need to get the width and height of the WebView and pass them in the query string of the URL loaded into the WebView. I found a way to do this in onResume (). Since the width and height are not calculated at this point, I send Runnable to the WebView for the queue for after loading the user interface.

Here's my problem: when the orientation changes, I process it in onConfigurationChanged. When I try to publish Runnable in onConfigurationChanged for WebView, the width and height of the WebView become the old width and height of the orientation. At what point can I intercept the new width and height after changing the orientation?

+4
source share
3 answers

Use ViewTreeObserver , for an example see this answer: fooobar.com/questions/299175 / ...

+2
source

Try it onPostResume. This is called after onResume, which should be called when it is ready to put it on the screen.

0
source

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

0
source

Source: https://habr.com/ru/post/1437875/


All Articles