Leave app only in portrait mode [closed]

1

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

    
asked by anonymous 28.03.2017 / 23:23

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" />
    
28.03.2017 / 23:26
2

In addition to the way Leofontes has demonstrated by setting the android:screenOrientation attribute to portrait in its <activity> found in AndroidManifest.xml , you can also programmatically insert using the setRequestedOrientation . Here's an example:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Then it would look like this onCreate() :

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

Note : A while back Google has released a note that applications that work 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 issues, to create layouts that support the two guidelines simultaneously.

    
29.03.2017 / 02:29