我有一个小班,需要跟踪设备的宽度和高度。Android display.getWidth/height为设备返回错误的尺寸?
public class BrScreenMetrics {
public static int screenX=0;
public static int screenY=0;
public static void setMetrics(Activity activity)
{
WindowManager w = activity.getWindowManager();
Display d = w.getDefaultDisplay();
screenX = d.getWidth();
screenY = d.getHeight();
}
}
随着每一个新的活动我unvoke行:
BrScreenMetrics.setMetrics(this);
哪些更新上旋转等方面的价值观......这个伟大的工程,但它返回320x522,不我的愿望是480x800。 我在做什么错?
轻微更新:
我试了一下,此代码使用以及机器人自己的指标类:
public static void setMetrics(Activity activity)
{
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
screenX = metrics.widthPixels;
screenY = metrics.heightPixels;
}
,但它仍然是320x522 :(
看到http://stackoverflow.com/questions/5078808/android-showing-wrong-screen-resolution – 2011-05-19 12:47:36