Android怎样判断当前屏幕是否为横屏状态

2025-04-02 20:38:56
推荐回答(1个)
回答1:

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);//强制为横屏}