3

什么是或在哪里可以找到最流行的设备 dpi 规格?我有一个布局,其中 ImageView 使用 dp 值参数化,为了提供最适合任何设备的服务器,给定特定像素参数可以生成必要的图像。

因此,关于px = dp * (dpi / 160)我需要定义最流行的 dpi 变体来计算服务器的像素数据。

谢谢。

4

2 回答 2

1

您实际上可以使用所需的确切大小查询服务器。

float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, intContainingYourDPs, getResources().getDisplayMetrics());
于 2012-10-10T09:53:05.780 回答
0

// 这些是 Google API 唯一支持的密度。

设备制造商可以为那里的设备提供自己的密度

假设 Galaxy 3 是306 dpi,但 android 会将其视为306/160=1.9

所以它DENSITY_XHIGH会从 xhdpi 获取资源。

public static final int DENSITY_DEFAULT
Since: API Level 4
The reference density used throughout the system.
Constant Value: 160 (0x000000a0)

public static final int DENSITY_HIGH
Since: API Level 4
Standard quantized DPI for high-density screens.
Constant Value: 240 (0x000000f0)

public static final int DENSITY_LOW
Since: API Level 4
Standard quantized DPI for low-density screens.
Constant Value: 120 (0x00000078)

public static final int DENSITY_MEDIUM
Since: API Level 4
Standard quantized DPI for medium-density screens.
Constant Value: 160 (0x000000a0)

public static final int DENSITY_TV
Since: API Level 13
This is a secondary density, added for some common screen configurations. It is recommended that applications not generally target this as a first class density -- that is, don't supply specific graphics for this density, instead allow the platform to scale from other densities (typically DENSITY_HIGH) as appropriate. In most cases (such as using bitmaps in Drawable) the platform can perform this scaling at load time, so the only cost is some slight startup runtime overhead.

This density was original introduced to correspond with a 720p TV screen: the density for 1080p televisions is DENSITY_XHIGH, and the value here provides the same UI size for a TV running at 720p. It has also found use in 7" tablets, when these devices have 1280x720 displays.    
Constant Value: 213 (0x000000d5)

public static final int DENSITY_XHIGH
Since: API Level 9
Standard quantized DPI for extra-high-density screens.
Constant Value: 320 (0x00000140)

public static final int DENSITY_XXHIGH
Since: API Level 16
Standard quantized DPI for extra-extra-high-density screens. Applications should not generally worry about this density; relying on XHIGH graphics being scaled up to it should be sufficient for almost all cases.
Constant Value: 480 (0x000001e0)
于 2012-10-10T10:54:31.637 回答