android获得屏幕的宽度和高度
参考自牛客网:https://www.nowcoder.com/test/question/done?tid=21050533&qid=49668#summary
1、通过WindowManager获取
DisplayMetrics dm = new DisplayMetrics();
heigth = dm.heightPixels;
width = dm.widthPixels;
2、通过Resources获取
DisplayMetrics dm = getResources().getDisplayMetrics();
heigth = dm.heightPixels;
width = dm.widthPixels;
3、获取屏幕的默认分辨率
Display display = getWindowManager().getDefaultDisplay();
heigth = display.getWidth();
width = display.getHeight();
4、通过类直接取
getWindowManager().getDefaultDisplay().getMetrics(dm);