gpt4 book ai didi

android - 以英寸为单位的声明尺寸与使用 DisplayMetrics 获得的尺寸之间的差异

转载 作者:行者123 更新时间:2023-11-30 02:54:43 24 4
gpt4 key购买 nike

我有一个 Samsung Galaxy S4 Active

当我在Android上执行时,如下代码:

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width=dm.widthPixels;
int height=dm.heightPixels;
int dens=dm.densityDpi;
double wi=(double)width/(double)dens;
double hi=(double)height/(double)dens;
double x = Math.pow(wi,2);
double y = Math.pow(hi,2);
double screenInches = Math.sqrt(x+y);

我得到

width = 1080
heigh = 1920
dens = 480

那么,使用的公式是否正确,screenInches 是 4.589。但是规范说 screenInches 尺寸是 5。

我也试过我的 Samsung Galaxy SII这给了我:

width = 480
heigh = 800
dens = 240

对应于 3.887 的 screenInches 而不是 4.3(如规范中所述)

为什么以英寸为单位的申报尺寸与我获得的尺寸之间存在差异?

编辑:似乎 densityDpi 返回以下值之一:(120、160、213、240、320、480 或 640 dpi)。

最佳答案

我认为您无法从 DisplayMetrics.densityDpi 获得真实的屏幕密度。它只能返回一个特定的常量值。 DisplayMetrics documentation说是

The screen density expressed as dots-per-inch. May be either DENSITY_LOW, DENSITY_MEDIUM, or DENSITY_HIGH.

但是Android Compatibility Definition Document (CDD).提供更全面的解释

Screen Density
The Android UI framework defines a set of standard logical densities to help application developers target application resources. Device implementations MUST report one of the following logical Android framework densities through the android.util.DisplayMetrics APIs, and MUST execute applications at this standard density.
> 120 dpi, known as 'ldpi'
> 160 dpi, known as 'mdpi'
> 213 dpi, known as 'tvdpi'
> 240 dpi, known as 'hdpi'
> 320 dpi, known as 'xhdpi'
> 400 dpi, known as '400dpi'
> 480 dpi, known as 'xxhdpi'
> 640 dpi, known as 'xxxhdpi'
Device implementations SHOULD define the standard Android framework density that is numerically closest to the physical density of the screen, unless that logical density pushes the reported screen size below the minimum supported. If the standard Android framework density that is numerically closest to the physical density results in a screen size that is smaller than the smallest supported compatible screen size (320 dp width), device implementations SHOULD report the next lowest standard Android framework density.

您可以从 DespalyMetrics.xdpi 获得 X 和 Y 维度上每英寸屏幕的精确物理像素和 DespalyMetrics.ydpi

关于android - 以英寸为单位的声明尺寸与使用 DisplayMetrics 获得的尺寸之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23475200/

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