一、通過(guò)WindowManager獲取屏幕的寬高
//context的方法沦寂,獲取windowManager
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
//獲取屏幕對(duì)象
Display defaultDisplay = windowManager.getDefaultDisplay();
//獲取屏幕的寬、高烦磁,單位是像素
int width = defaultDisplay.getWidth();
int height = defaultDisplay.getHeight();
二廓块、通過(guò)Resources對(duì)象
//獲取資源對(duì)象
Resources resources = getResources();
//獲取屏幕數(shù)據(jù)
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
//獲取屏幕寬高桃焕,單位是像素
int widthPixels = displayMetrics.widthPixels;
int heightPixels = displayMetrics.heightPixels;
//獲取屏幕密度倍數(shù)
float density = displayMetrics.density;