获取宽高(不加上虚拟键):
Display display = mWindowManager.getDefaultDisplay();
width_x = display.getWidth();
height_y = display.getHeight();
if (GameSDK.getSdkIsLandscape() == true) {
if (width_x < height_y) {
int i = width_x;
width_x = height_y;
height_y = i;
}
} else {
if (width_x > height_y) {
int i = width_x;
width_x = height_y;
height_y = i;
}
}
获取屏幕分辨率Dpi:
private String getDpi()
{ String dpi=null;
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.widthPixels+"*"+dm.heightPixels;
}catch(Exception e){
e.printStackTrace();
}
return dpi;
}