屏幕密度和图像尺寸

Screen densities and images dimensions

嗨Android开发人员,

我想知道如何选择drawables的尺寸;例如,我有一张我想插入到我的应用程序中的图像,图像应该插入到 xxhdpi、xhdpi、hdpi、mdpi 和 ldpi 中的尺寸(像素)是多少?

我在 GitHub 上分析了很多 android 应用程序,它们针对不同的密度使用随机图像大小(像素)。

我建议你阅读this answer。它包含决定使用哪些单位所需的所有信息。 TL;DR 是:永远不要使用像素的绝对值,而是对视图(包括图像)使用 dp 单位,对文本使用 sp。

支持多设备已涵盖here

另请查看 Material Design Guidelines 以了解图标、边距等的常用尺寸

To create alternative bitmap drawables for different densities, you should follow the 3:4:6:8:12:16 scaling ratio between the six generalized densities. For example, if you have a bitmap drawable that's 48x48 pixels for medium-density screens, all the different sizes should be:

  • 36x36 (0.75x) for low-density
  • 48x48 (1.0x baseline) for medium-density
  • 72x72 (1.5x) for high-density
  • 96x96 (2.0x) for extra-high-density
  • 144x144 (3.0x) for extra-extra-high-density
  • 192x192 (4.0x) for extra-extra-extra-high-density

来源:https://developer.android.com/guide/practices/screens_support.html#DesigningResources

最简单的方法是使用 Android Asset Studio。它将为相应的屏幕密度生成所有所需的图像分辨率

https://romannurik.github.io/AndroidAssetStudio/