I'm developing an app which supports only two orientations, portrait and reverse portrait, so I wrote "sensorPortrait
" in my manifest, and it works well.
The problem is, I want to use different layouts for these two orientations.
Enabling sensorPortrait
disables the "onConfigurationChange
" call.
I use:
orientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int i) {
int newOrientation = getScreenOrientation();
if (newOrientation != orientation) {
orientation = newOrientation;
if (newOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
...
setContentView(R.layout.main);
} else if (newOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
...
setContentView(R.layout.main_reverse_portrait);
}
}
}
};
orientationEventListener.enable();
The problem is that this code is being called AFTER changing orientation, so when the user rotates the phone at first they see the previous layout, rotated automatically by Android, and then the correct layout. It looks unacceptable, do you know how to fix it?