My problem:
For some requirements, I need two different xml layouts for my activity:
- One for Landscape mode.
- And one more for the landscape-reverse mode (inverted landscape).
Unfortunately, Android does not allow creating a separate layout for landscape reverse (as we can do for portrait and landscape orientation with layout-land and layout-port ).
AFAIK, the only way is to change action-xml from java code.
What I tried:
1) Override the onConfigurationChanged() method to determine orientation changes, but I cannot figure out if it is Landscape or Landscape-reverse:
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { Log.d("TEST","Landscape"); } }
(Whith android:configChanges="keyboardHidden|orientation|screenSize|layoutDirection" in the activity tag in the manifest)
2) Use OrientationEventListener with SENSOR_DELAY_NORMAL as suggested in this answer , but the device orientation changes before entering my if blocks, so I get a deferred view update:
mOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL){ @Override public void onOrientationChanged(int orientation) { if (orientation==0){ Log.e("TEST", "orientation-Portrait = "+orientation); } else if (orientation==90){ Log.e("TEST", "orientation-Landscape = "+orientation); } else if(orientation==180){ Log.e("TEST", "orientation-Portrait-rev = "+orientation); }else if (orientation==270){ Log.e("TEST", "orientation-Landscape-rev = "+orientation); } else if (orientation==360){ Log.e("TEST", "orientation-Portrait= "+orientation); } }};
My question is:
Is there a better solution for changing the type of activity between "Landscape" and "Landscape-reverse" orientation?
Any suggestions are welcome.