如何知道设备的密度?

11
我们可以在Android中获取分辨率,但是如何知道设备(屏幕)的密度?谢谢。
1个回答

27

执行以下代码:

float scale = getApplicationContext().getResources().getDisplayMetrics().density;

并检查 scale 的值:

  • 0.75 表示低密度
  • 1.0 表示标准(中等)密度
  • 1.5 表示高(大)密度
  • 2.0 表示额外高密度
  • 3.0 表示额外额外高密度
  • 4.0 表示额外额外额外高密度

有关更多信息,请参见文档


嗨Chirag,如果可能的话,请查看这篇帖子:http://stackoverflow.com/questions/4758278/redraw-image-on-canvas-on-touch-event - Hitendra
今天还有tvdpi和xhdpi。将来可能会有更多。更多信息请参见:http://developer.android.com/reference/android/util/DisplayMetrics.html - android developer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接