开发者

Has anyone used xdpi, ydpi and gotten correct results

I'm wondering if anyone out开发者_如何学JAVA there has used xdpi and ydpi and gotten the actual physical dpi of the device?

Thanks


It is correct on my Nexus One, but not on my Galaxy S2 (T-mobile). So I wrote some code to fall back on the less accurate measurement. Basically, if xdpi and ydpi are not within 5% of the generic density, use the generic.

Who says fragmentation isn't a problem? Google's product test suite for certification must not exercise this part of the API.

  DisplayMetrics dm = new DisplayMetrics();
  ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm);
  float density = dm.density;
  density = density * 160;
  float xdpi = dm.xdpi;
  float ydpi = dm.ydpi;
  float errX = Math.abs((xdpi / density) - 1f);
  float errY = Math.abs((ydpi / density) - 1f);
  if (errX > .05 && errY > .05)
  {
     xdpi = density;
     ydpi = density;
  }


I haven't. xdpi and xdpi are totally wrong in all phones I've tried it on. It makes no sense.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜