I want to be able to detect whether the phone is in landscape or portrait mode, but I don't want my activity and all my buttons to rotate along.
This code detects the rotation, but it also rotates the screen:
Display display = getWindowManager().getDefaultDisplay();
int rotation = display.getRotation();
rotVal.setText("Rotation: " + rotation);
I tried to lock the activity in portrait mode with this in the MainActivity, but then rotation
value doesn't change. (Makes sense I guess)
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
I also tried android:screenOrientation="portrait"
in the manifest file but the rotVal
stays zero.
This answer have a rotating animation, and I don't want that. I want the screen to stay as it is even in landscape mode, no rotating, no animation, etc.
This answer doesn't work. When I rotate the phone, the rotVal
stays zero.
Is there a way to detect the orientation without rotating/recreating the layout?