美文网首页
Android极速开发之手机屏幕

Android极速开发之手机屏幕

作者: Javen205 | 来源:发表于2016-08-27 22:42 被阅读51次
    • 获取屏幕宽高
    • 手机横竖屏的判断
    public class ScreenUtils {
    
        public static int getWidth(Context context) {
            WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics outMetrics = new DisplayMetrics();
            manager.getDefaultDisplay().getMetrics(outMetrics);
    
            return outMetrics.widthPixels;
        }
    
        public static int getHeight(Context context) {
            WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics outMetrics = new DisplayMetrics();
            manager.getDefaultDisplay().getMetrics(outMetrics);
    
            return outMetrics.heightPixels;
        }
    }
    
    
    public class ConfigUtils {
    
        public static boolean isOrientationPortrait(Context context) {
            if (context.getResources().getConfiguration().orientation ==
                    Configuration.ORIENTATION_PORTRAIT) {
                return true;
            }
            return false;
        }
    
        public static boolean isOrientationLandscape(Context context) {
            if (context.getResources().getConfiguration().orientation ==
                    Configuration.ORIENTATION_LANDSCAPE) {
                return true;
            }
            return false;
        }
    }
    

    相关文章

      网友评论

          本文标题:Android极速开发之手机屏幕

          本文链接:https://www.haomeiwen.com/subject/vbetettx.html