Portrait for phone, landscape for Tablet (Android-Layout)

后端 未结 5 1701
臣服心动
臣服心动 2020-11-30 04:09

So I\'m making an application for Android and I want to force Landscape orientation for tablets and Portrait orientation for phones. However, it seems as though I can only

5条回答
  •  心在旅途
    2020-11-30 04:36

    Setting a particular orientation based on device density may not work because there are phones which have higher densities than tablets.

    What I did was to disable the device's orientation sensor by setting the attribute in the activity tag in the manifest file like this:

    android:screenOrientation="nosensor"
    

    When you run your app, by default portrait orientation is set for phones and landscape for tablets(and hence it'll select the xml file from layout-xlarge-land). And since you've set an orientation lock, it remains in this orientation.

提交回复
热议问题