Android 如何选择屏幕密度

How Android choose between screen density

例如,我在ldpimdpixhdpi文件夹中提供了一些图像。

当我在 hdpi 密度的设备上 运行 应用程序时,它将选择哪个资源 - ldpimdpi?

取自http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch

If no matching resource is available, the system uses the default resource and scales it up or down as needed to match the current screen size and density The "default" resources are those that are not tagged with a configuration qualifier. For example, the resources in drawable/ are the default drawable resources. The system assumes that default resources are designed for the baseline screen size and density, which is a normal screen size and a medium-density. As such, the system scales default density resources up for high-density screens and down for low-density screens, as appropriate. However, when the system is looking for a density-specific resource and does not find it in the density-specific directory, it won't always use the default resources. The system may instead use one of the other density-specific resources in order to provide better results when scaling. For example, when looking for a low-density resource and it is not available, the system prefers to scale-down the high-density version of the resource, because the system can easily scale a high-density resource down to low-density by a factor of 0.5, with fewer artifacts, compared to scaling a medium-density resource by a factor of 0.75.

在这种情况下 android 选择 **mdpi*。 您可以阅读更多关于 How Android Finds the Best-matching Resource

假设MDPI为1,那么LDPI为0.75,HDPI为1.5。这意味着如果你有一个可绘制对象,比如说,在 MDPI 屏幕上它是 50x50,它在 LDPI 屏幕上必须是 ~37x37,在 HDPI 屏幕上必须是 75x75。

如果您没有为每种密度提供特殊的绘图,Android 将自动缩放最接近的可用绘图。

您不应认为设备的 DPI 与屏幕尺寸 and/or 像素数 and/or 分辨率 and/or 宽高比有任何关系。一个设备可以非常小并且有一个 HDPI 屏幕或者非常大并且有一个 LDPI 屏幕

ldpi Resources for low-density (ldpi) screens (~120dpi). mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.) hdpi Resources for high-density (hdpi) screens (~240dpi). xhdpi Resources for extra-high-density (xhdpi) screens (~320dpi). xxhdpi Resources for extra-extra-high-density (xxhdpi) screens (~480dpi). xxxhdpi Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi). Use this for the launcher icon only, see note above.

请检查http://developer.android.com/guide/practices/screens_support.html and SO answer