获取屏幕原始尺寸高度,包括虚拟功能键高度,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 private int getDpi() { int dpi = 0 ; Display display = getWindowManager().getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); @SuppressWarnings ( "rawtypes" ) Class c; try { c = Class.forName( "android.view.Display" ); @SuppressWarnings ( "unchecked" ) Method method = c.getMethod( "getRealMetrics" ,DisplayMetrics. class ); method.invoke(display, dm); dpi=dm.heightPixels; } catch (Exception e){ e.printStackTrace(); } return dpi; }通过两个高度的对比,可以知道设备是否拥有虚拟功能建,Android4.0以后出现的虚拟功能键,对界面布局的兼容性有较大影响,记录之。