//获取屏幕的宽度旧方法,已废弃
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
int screenWidth = wm.getDefaultDisplay().getWidth();
System.out.println("screenWidth:" + screenWidth);
//获取屏幕的宽高新方法1
Point size = new Point();
wm.getDefaultDisplay().getSize(size);
int screenWidth1 = size.x;
int screenHeight = size.y;
System.out.println("screenWidth1:" + screenWidth1);
//获取屏幕的宽高新方法2
DisplayMetrics displaymetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(displaymetrics);
int screenWidth2 = displaymetrics.widthPixels;
int screenHeight2 = displaymetrics.heightPixels;
System.out.println("screenWidth2:" + screenWidth2);
android 获取屏幕尺寸
最新推荐文章于 2023-06-27 16:25:48 发布