开发者

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

W开发者_开发问答henever I turn the device sideways, everything in my app also turns and becomes distorted. How do I lock it into vertical?


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>


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.


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.


Take a look at these SOqs:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜