参考文章:https://blog.csdn.net/u012527802/article/details/44645731
前面有几个方法已经过时了,我们使用新的方法。
this是一个activity对象
WindowManager manager = this.getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
int width2 = outMetrics.widthPixels;
int height2 = outMetrics.heightPixels;