I would like to now if the is any possible way to trigger an event when the layout is being redrawn because of the event of switching directly from landscape right orientation to landscape left orientation.
I tried the OrientationEventListener. The problem is that it triggers to fast. I am doing UI changes and they happen before the landscape is being redrawn, and it looks bad.
I could just add some delay on the changes but depending on the phone that change could last more or less.
For the onConfigurationChanged the timing is perfect, but of course it only works for portrait to landscape or landscape to portrait.
My application must not pause in this change, so using onPause, onStop, etc is not an option.
So I am looking for an event similar to onConfigurationChanged that also covers landscape right to landscape left changes.
You can do the following:
You can use handler.post(runnable), that way your UI changes shouldn`t happen before the redrawn, but will be queued on the main thread and executed after it finishes drawing.
If this still doesn`t help out you can try a difficult and ugly way to make use of orientation listener and the onLayout() method :)
I think you almost get it. I do not know if you do similar thing, but this one let you doing UI change as soon as the orientation change. I did this example for only changing from
ROTATION_270
toROTATION_90
, but you can add to the code so that I can cover all cases fromPORTRAIT
toREVERSE_PORTRAIT
etc... My example is simply changing a textview from "Landscape" to "reverse landscape" when orientation changes.XML
Code
I got some idea maybe there is a function that is called before the orientation change that we can override. I will play around and if I find one I will update the answer.
You can use DisplayListener which gets triggered in this case, as described in this answer: https://stackoverflow.com/a/23612548/2942294