private void getScreenSize() {
//1、通过WindowManager获取
WindowManager manager = this.getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
int width = outMetrics.widthPixels;
int height = outMetrics.heightPixels;
Log.i(TAG, "Method 1: height::" + height + " width::" + width);
//2、通过Resources获取
DisplayMetrics dm1 = getResources().getDisplayMetrics();
int height1 = dm1.heightPixels;
int width1 = dm1.widthPixels;
Log.i(TAG, "Method 2: height::" + height1 + " width::" + width1);
//3、获取屏幕的默认分辨率
Display display = getWindowManager().getDefaultDisplay();
int height2 = display.getWidth();
int width2 = display.getHeight();
Log.i(TAG, "Method 3: height::" + height2 + " width::" + width2);//Method 3: height::1080 width::1920
}
版权声明:本文为优快云博主「游走的大千世界的烤腰子」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/zhangqunshuai/article/details/80838897