How do you prevent the android screen from being turned sideways?

删除回忆录丶 提交于 2019-12-23 01:41:49

问题


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


来源:https://stackoverflow.com/questions/4417418/how-do-you-prevent-the-android-screen-from-being-turned-sideways

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!