gpt4 book ai didi

android - 如何获取屏幕DPI

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:07:36 25 4
gpt4 key购买 nike

我正在尝试获取屏幕的 dpi,但到目前为止它无法正常工作。我试过:

    DisplayMetrics dm = new DisplayMetrics();
mainContext.getWindowManager().getDefaultDisplay().getMetrics(dm);
SCREEN_DPI = dm.densityDpi;

但在 Samsung Galaxy Tab 10.1 和 Samsung Galaxy S I9000 上,SCREEN_DPI 都等于 160。我也尝试了 SCREEN_DPI = dm.density,但我得到的值是 1.0两种情况。

如有任何帮助,我们将不胜感激。

最佳答案

重复 this question

Though Android doesn't use a direct pixel mapping, it uses a handful of quantized Density Independent Pixel values then scales that to the actual screen size. So the density property will be one of those constants (120, 160, or 240 dpi).

If you need the actual density (perhaps for an OpenGL app) you can get it from the xdpi and ydpi properties for horizontal and vertical density respectively.

关于android - 如何获取屏幕DPI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8186951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com