Question

I have an activity with custom rotation handling with a WebView. The problem is that I need to trigger an event after the layout is redrawn due to the orientation change. In my rotation handler, I'm detecting elements wider than the webview. When triggering this handler in onConfigurationChanged, view size is not recalculated yet so I'm getting width before rotation.

I have two bad solutions:

  • calculate the size programatically from the other sceen dimension and all paddings and other views, but it is too complicated and ineffective.
  • trigger the handler with some timeout, but it is ugly with long timeout and not reliable with short timeout.

Is there some event triggered after the layout is redrawn?

Thanks in advance.

Was it helpful?

Solution

What about View.onAttachedToWindow()?

If that does not work (the documentation says it might even be called before onMeasure(), so I'm not sure whether the timing and freuqency suit your needs), you could maybe hook into the layout process, by extending one of the View objects you use, and override View.onLayout to schedule a UI thread callback. I would prepare for a multiple occurence though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top