Android 获取横竖屏状态

方法一:

/**
     * 获取当前屏幕是否是横屏(默认)
     *
     * @param context
     * @return
     */
    public static boolean isCurOriLand(Context context) {
    
    
        boolean isLand = true;
        try {
    
    
            Configuration mConfiguration = context.getResources().getConfiguration(); //获取设置的配置信息
            int ori = mConfiguration.orientation; //获取屏幕方向
            if (ori == mConfiguration.ORIENTATION_LANDSCAPE) {
    
    
                //横屏
                isLand = true;
            } else if (ori == mConfiguration.ORIENTATION_PORTRAIT) {
    
    
                //竖屏
                isLand = false;
            }
        } catch (Exception e) {
    
    
            e.printStackTrace();
        }
        return isLand;
    }

方法二:

if (getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
    
    
	//当前状态为竖屏
}else{
    
    
	//当前状态为横屏
}

猜你喜欢

转载自blog.csdn.net/qq_27494201/article/details/127263990