简体   繁体   English

如何找到Android屏幕的PPI

[英]how to find the ppi of an android screen

I have a very simple question. 我有一个非常简单的问题。

All I'm looking for is the code to find the PPI of an android screen, i know how to find the height and width in pixels but not the amount of pixels per inch. 我正在寻找的只是用于查找android屏幕的PPI的代码,我知道如何查找以像素为单位的高度和宽度,而不是每英寸的像素数。 I need this to help me find the diagonal of the screen. 我需要这个来帮助我找到屏幕的对角线。 I tried but it doesn't seem to work 我尝试过,但似乎没有用

DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); 

int  ppi = (int) displayMetrics.density;

Maybe like this? 也许是这样吗?

   DisplayMetrics metrics = getResources().getDisplayMetrics();

See here 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM