屏幕尺寸(高、宽)

阅读更多

Display display = getWindowManager().getDefaultDisplay();
display.getWidth();//返回px值
display.getHeight();//返回px值
display.getRotation();返回0或1,0表示竖屏,1表示横屏

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
dm.density;
dm.heightPixels;
dm.widthPixels;

 

看看上面两者的关系

public void getMetrics(DisplayMetrics outMetrics) {
	outMetrics.widthPixels  = getWidth();
	outMetrics.heightPixels = getHeight();
	outMetrics.density      = mDensity;
	outMetrics.densityDpi   = (int)((mDensity*DisplayMetrics.DENSITY_DEFAULT)+.5f);
	outMetrics.scaledDensity= outMetrics.density;
	outMetrics.xdpi         = mDpiX;
	outMetrics.ydpi         = mDpiY;
}
//仅仅是将Display的内部值赋给了DisplayMetrics的属性值
 

你可能感兴趣的:(屏幕尺寸(高、宽))