android - 中性可绘制文件夹中应放置哪种图像尺寸?

标签 android android-layout user-interface drawable

中性可绘制文件夹中应放置多大尺寸的图像?

我有一个5 个不同 版本的图标文件:

  • 24x24 = ldpi
  • 32x32 = mdpi
  • 48x48 = 高清像素
  • 64x64 = xhdpi
  • 96x96 = xxhdpi

另一方面,我有6 个不同的 文件夹:

  • /可绘制
  • /drawable-ldpi
  • /drawable-mdpi
  • /drawable-hdpi
  • /drawable-xhdpi
  • /drawable-xxhdpi

5 个文件和 6 个文件夹意味着要么一个文件夹必须保持为空(哪个?),要么一个文件必须使用两次?

这就是docs说:

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.

好的,mdpi版本应该放在drawable-mdpi,ldpi放在drawable-ldpi等等,这是没有问题的。但是哪个版本进入中性文件夹?

我应该将 xxhdpi 文件放在那里(如果找不到匹配项则缩小)?那 -xxhdpi 文件夹呢?将其留空还是将文件也放在那里?

最佳答案

默认的 /drawable 文件夹需要 mdpi 图像。主要用于 2 种情况:

  1. To have non-density dependent images. eg: selectors, which indirectly link to images from density named folders again.

  2. To have all the images in only this folder and ignore all the other drawable folders. In which case the images will be scaled depending on the screen density.

针对您的情况:

You can keep only xml files like selectors in the default /drawable folder and other images in their respective folders

关于android - 中性可绘制文件夹中应放置哪种图像尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24199128/

相关文章:

ios - 对于 UIButton,我同时使用了标题和图像。我希望标题先于图像

android - `remember` 是否仅适用于 `MutableState` 变量?

Android NDK SIGILL 在 ARMv6 设备上的 fpu 指令崩溃

android - 屏幕旋转后 ListFragment getListView() 返回 null

android - Textview 就像一个终端

html - 一个元素不能居中,因为有些东西看起来不对

QT:没有这样的插槽

java - 如何使用 viewModel 中的观察者方法解决 "anonymous class derived from observer"错误

android - 在 imageView 中显示下载的图像

android - R.attr.colorPrimary 颜色类型的预期资源