3

I want my Android App to remain in landscape mode only. So, I used this in my manifest.xml file:

android:screenOrientation="landscape"

However, it locked the app in the landscape mode and even when I rotate the screen by 180 degrees, it remains in same orientation. Is there some way so that only portrait mode is disabled, while the two landscapes mode are allowed?

Kshitij
  • 63
  • 8
  • check this out--> http://stackoverflow.com/questions/4561527/i-want-to-make-my-application-only-in-landscape-in-android http://stackoverflow.com/questions/4858026/android-alternate-layout-xml-for-landscape-mode – Aradhna Jun 25 '14 at 06:35
  • 2
    @aradhna Please remove the comment as both the links are of no use. – CodeWarrior Jun 25 '14 at 06:41

3 Answers3

5

In your manifest, change your activity screenOrientation tag to android:screenOrientation="sensorLandscape" and you are done.

This will keep the application in the landscape mode in both direction according to the sensor of mobile.

Jagdeep Singh
  • 1,200
  • 1
  • 16
  • 34
0

In addition to Jagdeep Singh's answer,from the docs:

"sensorLandscape"

Landscape orientation, but can be either normal or reverse landscape based on the device sensor. Added in API level 9.

and the following note would be helpful:

Note: When you declare one of the landscape or portrait values, it is considered a hard requirement for the orientation in which the activity runs. As such, the value you declare enables filtering by services such as Google Play so your application is available only to devices that support the orientation required by your activities. For example, if you declare either "landscape", "reverseLandscape", or "sensorLandscape", then your application will be available only to devices that support landscape orientation. However, you should also explicitly declare that your application requires either portrait or landscape orientation with the <uses-feature> element. For example, <uses-feature android:name="android.hardware.screen.portrait"/>. This is purely a filtering behavior provided by Google Play (and other services that support it) and the platform itself does not control whether your app can be installed when a device supports only certain orientations.
Community
  • 1
  • 1
SMR
  • 6,628
  • 2
  • 35
  • 56
0

on onCreate method of each activity :

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118