在安卓中有两种横竖屏切换的方式:
1.在Manifest.xml中设置
<activity
android:name="xxx.xxx.xxxActivity"
android:screenOrientation="portrait"/>
*screenOrientation:属性共有两种*
- android:screenOrientation=”portrait” 始终竖屏
- android:screenOrientation=”landscape” 始终横屏
2.在BaseActivity中设置
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
* setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);参数理解:*
- ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:始终竖屏
- ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:始终横屏