Configuration mConfiguration = this.getResources().getConfiguration(); //获取设置的配置信息int ori = mConfiguration.orientation; //获取屏幕方向if (ori == mConfiguration.ORIENTATION_LANDSCAPE) { //横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//强制为竖屏} else if (ori == mConfiguration.ORIENTATION_PORTRAIT) { //竖屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//强制为横屏}