如何知道设备的密度?

Hit*_*dra 10 android

嗨因为我们可以在Android中获得分辨率,但我们怎么知道设备的密度(屏幕)?

thnakx

chi*_*dev 26

执行以下代码:

float scale = getApplicationContext().getResources().getDisplayMetrics().density;
Run Code Online (Sandbox Code Playgroud)

并检查以下值scale:

  • 0.75意味着低密度
  • 1.0标准(中等)密度
  • 1.5意味着高(大)密度
  • 2.0意味着超高密度
  • 3.0意味着额外的高密度
  • 4.0意味着额外的额外高密度

有关详细信息,请参阅文档.