prashant prashant - 1 year ago 67
Android Question

How to keep the screen in landscape mode in Android

I have an activity which should always be displayed in Landscape mode. So i added


But the problem is when I rotate the device by 180 degrees, the display is inverted. is there a way to handle this issue so that the screen elements are always shown correctly.?

Answer Source

So just for everyone information, this is what i did.

  1. In Android manifest added android:screenOrientation="landscape".
  2. In on resume method add these lines of code
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getRotation();


This way my screen is always positioned correctly even if user holds the device upside down.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download