Android開發之強制橫屏和強制豎屏
阿新 • • 發佈:2018-11-16
強制豎屏設定
1.程式碼在Activity的onResume方法中新增如下程式碼
@Override
protected void onResume() {
/**
* 設定為橫屏
*/
if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
super .onResume();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
2.在配置檔案中對Activity節點新增android:screenOrientation屬性(landscape是橫向,portrait是縱向)
android:launchMode="singleTask" android:screenOrientation="portrait">
- 1
強制橫屏設定
1.程式碼在Activity的onResume方法中新增如下程式碼
@Override
protected void onResume() {
/**
* 設定為橫屏
*/
if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
super.onResume();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
2.在配置檔案中對Activity節點新增android:screenOrientation屬性(landscape是橫向,portrait是縱向)
android:launchMode="singleTask" android:screenOrientation="landscape">
強制豎屏設定
1.程式碼在Activity的onResume方法中新增如下程式碼
@Override
protected void onResume() {
/**
* 設定為橫屏
*/
if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
super.onResume();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10