屏幕尺寸(高、宽)
Java代码
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;
看看上面两者的关系
Sdk代码片段代码
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的属性值
作者“程序人生”
补充:移动开发 , Android ,