yan*_*008 3 height android screen width android-3.0-honeycomb
我的代码:
Display display = activity.getWindowManager().getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
System.out.println("screen width:"+displayMetrics.widthPixels);
System.out.println("screen heigth:"+displayMetrics.heightPixels);
Run Code Online (Sandbox Code Playgroud)
当我在android Honeycomb系统中运行这个程序时,输出是800和1232,但设备的屏幕是800_1280,我可以得到它吗?谢谢.
这段代码适合我(如果你不介意使用未记录的方法):
Display d = getWindowManager().getDefaultDisplay();
int width, height;
Method mGetRawH;
Method mGetRawW;
try {
mGetRawH = Display.class.getMethod("getRawWidth");
mGetRawW = Display.class.getMethod("getRawHeight");
width = (Integer) mGetRawW.invoke(d);
height = (Integer) mGetRawH.invoke(d);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
//You should care about orientation here
int o = getResources().getConfiguration().orientation;
if (o == Configuration.ORIENTATION_PORTRAIT) {
if (width > height) {
int tmp = width;
width = height;
height = tmp;
}
} else if (o == Configuration.ORIENTATION_LANDSCAPE) {
if (width < height) {
int tmp = width;
width = height;
height = tmp;
}
}
Log.d("d", "w=" + width + " h=" + height);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2969 次 |
| 最近记录: |