在开发Android的应用中,有时候需要限制横竖屏切换,此时只需要在AndroidManifest.xml文件中的Activity标签中加入android:screenOrientation=“landscape”
如下:
<activity
android:name="com.example.ui.LauncherActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:screenOrientation="landscape"限制此activity页面横屏显示
android:screenOrientation="portrait"限制此activity页面竖屏显示
android:screenOrientation设定该Activity的方向,该值可以是以下值中的任意值:
“unspecified”
---默认值,由系统选择显示的方向,在不同的设备可能会有所不同。
“landscape”
---横向
“portrait”
---竖向
“user”
---当前用户的首选方向
“behind”
---与在Activity堆栈下的Activity活动方向相同
“sensor”
---根据物理方向传感器确定方向,取决用户手持的方向,当用于转动设备时,它会跟随改变
“nosensor”
---不经物理方向传感器确定方向,该传感器被忽略,所以当用户转动设备,显示不会跟随改动,除了这个区别,系统选择使用相同的政策取向对于未指定设置,系统根据未指定(“unspecifiled”)设定选择相同的显示方向。