How to Lock Android App's Orientation to Portrait in Phones and Landscape in Tablets?

前端 未结 9 1695
自闭症患者
自闭症患者 2020-12-02 08:44

I am developing an Android app whose orientation I don\'t want changed to landscape mode when the user rotates the device. Also, I want the locked orientation to be portrait

9条回答
  •  被撕碎了的回忆
    2020-12-02 09:10

    I can see you have accepted an answer which doesn't solve your problem entirely:

    android:screenOrientation="portrait" 
    

    This will force your app to be portrait on both phones and tablets.

    You can have the app forced in the device's "preferred" orientation by using

    android:screenOrientation="nosensor"
    

    This will lead to forcing your app to portrait on most phones phones and landscape on tablets. There are many phones with keypads which were designed for landscape mode. Forcing your app to portrait can make it almost unusable on such devices. Android is recently migrating to other types of devices as well. It is best to just let the device choose the preferred orientation.

提交回复
热议问题