Android 获取屏幕宽高的方式

Activity中:

第一种方法:

WindowManager windowManage = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

第二种方法:

WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
Point outSize = new Point();
display.getSize(outSize); //这个方法minAPI 13
int width = outSize.x;
int height = outSize.y;

第三种方法:

DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int width = metric.widthPixels;
int height = metric.heightPixels;

你可能感兴趣的:(Android 获取屏幕宽高的方式)