Leave app only in portrait mode

Asked

Viewed 1,453 times

1

How to make the application work only in portrait mode, and when turning the screen nothing happens ?

  • http://stackoverflow.com/questions/3723823/i-want-my-android-application-to-be-only-run-in-portrait-mode

2 answers

7


Just add it to your Androidmanifest.XML android:screenOrientation="portrait":

<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" />

2

Beyond the way Leofontes demonstrated defining the attribute android:screenOrientation as portrait in his <activity> located in the AndroidManifest.xml, you can also insert programmatically using the method setRequestedOrientation. Take an example:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Then I’d stay this way onCreate():

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

Note: A while ago Google released a note that applications running only in one mode, being Portrait or Landscape, would be less visible to download (when I find the news I leave the link here). So it’s important, you think about these questions, to create layouts supporting both guidelines simultaneously.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.