How do you prevent the android screen from being t

2019-06-08 03:35发布

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

4条回答
聊天终结者
2楼-- · 2019-06-08 03:49

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.

查看更多
Emotional °昔
4楼-- · 2019-06-08 03:52

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>
查看更多
男人必须洒脱
5楼-- · 2019-06-08 04:05

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.

查看更多
登录 后发表回答