How can I disable landscape mode for some of the views in my Android app?
Add android:screenOrientation="portrait" to the activity you want to disable landscape mode in.
If you want to develop an application in portrait mode, add screenOrientation inside application tag. In the above result it is showing only portrait mode. now turn your device it not going to change the view according to orientation.
The Basic SolutionsIf the screen rotation is already on try turning it off and then on again. To check this setting, you can swipe down from the top of the display. If it's not there, try going to Settings > Display > Screen rotation.
Add android:screenOrientation="portrait"
to the activity in the AndroidManifest.xml. For example:
<activity android:name=".SomeActivity" android:label="@string/app_name" android:screenOrientation="portrait" />
Since this has become a super-popular answer, I feel very guilty as forcing portrait is rarely the right solution to the problems it's frequently applied to.
The major caveats with forced portrait:
retainInstance
fragments.So most apps should just let the phone sensors, software, and physical configuration make their own decision about how the user wants to interact with your app. A few cases you may still want to think about, though, if you're not happy with the default behavior of sensor
orientation in your use case:
nosensor
for the orientation. This forces landscape on most tablets and portrait on most phones, but I still wouldn't recommend this for most "normal" apps (some users just like to type in the landscape softkeyboard on their phones, and many tablet users read in portrait - and you should let them).sensorPortrait
may be better than portrait
for Android 2.3 (Gingerbread) and later; this allows for upside-down portrait, which is quite common in tablet usage.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With