How do you prevent the android screen from being t

2019-06-08 03:15发布

问题:

Whenever I turn the device sideways, everything in my app also turns and becomes distorted. How do I lock it into vertical?

回答1:

In your AndroidManifest.xml set the orientation on your Activity to portrait like this.

<activity android:name=".YourActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


回答2:

Whenever I turn the device sideways, everything in my app also turns and becomes distorted. How do I lock it into vertical?

Generally, you do not want to do that.

First, some users have devices with physical keyboards that only operate in landscape mode. Perhaps, for your app, that does not matter. However, any app that uses text input should support landscape mode for these users.

Second, few TVs will operate in portrait mode. It is reasonably likely that your app will look bad on Google TV when it starts supporting Android applications.

Third, even for users whose devices are not forcing them to use landscape, simply prefer to use landscape, for whatever reason.

All of these user bases will think less of applications that force portrait mode, and their opinions may be reflected in ratings on the Android Market.

Most applications should support portrait and landscape, through careful design of the existing layouts and by using res/layout-land/ to provide replacement layouts where a significant change is required.



回答3:

For the activity you have defined in the manifest, you need to set the android:screenOrientation.

Set it to portrait or landscape. Make sure it is not sensor.



回答4:

Take a look at these SOqs:

  • Disable screen rotating on Android
  • Prevent screen rotation on Android