android 横竖屏模式的设置

来源:互联网 发布:阿里云架设服务器 编辑:程序博客网 时间:2024/04/30 23:10

有的应用需要支持用户可以设定的横竖屏模式,可以用 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 实现。

String strSize = prefs.getString(this.getString(R.string.key_nes_video_orientation_option),this.getString(R.string.video_orientation_options_default_value));switch(Integer.parseInt(strSize)){case 0: // 强制横屏this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);break;case 1: // 强制竖屏this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);break;default:  // 系统默认方式break;}

以上代码建议配合 preference设置,放在 activity的 onResume 中。更多横竖屏模式可以参考 http://developer.android.com/reference/android/content/pm/ActivityInfo.html