解释drawable、drawable-ldpi、drawable-mdpi和drawable-hdpi的区别 [英] Explain the difference between drawable, drawable-ldpi, drawable-mdpi and drawable-hdpi

查看:41
本文介绍了解释drawable、drawable-ldpi、drawable-mdpi和drawable-hdpi的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对每个目录的用途有一个大致的了解,但我对概念不是很清楚,而且我有一些具体的问题.

I have a rough idea of what each of these directories are for, but I'm not really clear on the concept and I have some specific questions.

例如,每个目录的目标 DPI 是多少?当您创建资产时,它应该处于该目标 DPI 还是应该处于更正常的 72dpi 屏幕 DPI?如果您针对多个设备,将 PNG 放在 drawable 中是否合适,还是应该始终针对特定屏幕稍微定制多个版本?

For example, what are the target DPIs for each directory? When you create an asset, should it be at that target DPI or should it be at the more normal 72dpi screen DPI? If you're targeting multiple devices, is it ever appropriate to put a PNG in drawable or should you always have multiple versions slightly tailored to the specific screens?

谢谢.

推荐答案

正如其他人所建议的,Android 在线文档有很多关于此的文章.但是,我将尝试在此处列出一些快速且有用的提示:

As the others have suggested, the Android online documentation has great articles on this. However, I'm going to try and list here some quick and helpful tips:

  1. 考虑 MDPI 是 1.那么,LDPI 为0.75,HDPI 为1.5.这意味着,如果你有一个 drawable,比如在 MDPI 屏幕上的 50x50 在 LDPI 屏幕上它必须是 ~37x3775x75 在 HDPI 屏幕上,为了在每个屏幕上显示大致相同的物理尺寸(如果你在屏幕上放一把尺子,则为 2 厘米).此外,您的计算机屏幕很可能是 MDPI,这就是为什么建议从 MDPI 可绘制对象开始,然后调整它们的大小:可绘制对象的物理大小将非常接近您的计算机屏幕和 MDPI Android 设备.如果您在计算机和 HDPI 设备上查看 HDPI 可绘制对象,您会注意到它(同样,物理 - 在它的样式上放一把尺子)电脑屏幕.
  2. 如果您没有为每个密度提供特殊的可绘制对象,Android 将自动缩放最接近的可用对象.
  3. 您不应认为设备的 DPI 与屏幕尺寸和/或像素数和/或分辨率和/或纵横比有任何关系.一个设备可以非常小并且有一个 HDPI 屏幕,或者非常大并且有一个 LDPI 屏幕.这种密度差异的全部意义在于让事物在所有设备上看起来大小相同并非在所有设备上都相同.例如,如果一个可绘制对象在一个 MDPI 设备上填满整个屏幕,不要期望它在另一个 MDPI 设备上也这样做.此外,不要期望在不同的 DPI 设备上看到相同的东西".大多数 HDPI 设备实际上比低 DPI 设备具有更多空间.例如,如果 ListView 可以在 MDPI 设备上显示 5 个项目,它可能能够在 HDPI 设备上显示 6 个项目,尽管 ListView 项目具有相同的密度无关(即 HDPI 比 MDPI 大 1.5 倍)高度.
  1. Consider MDPI is 1. Then, LDPI is 0.75 and HDPI is 1.5. What that means is that if you have a drawable that is, say, 50x50 on a MDPI screen it will have to be ~37x37 on a LDPI screen and 75x75 on a HDPI screen, in order to appear at roughly the same physical size on each screen (i.e. 2cm if you put a ruler on the screen). Also, your computer screen is most probably MDPI, which is why it's recommended to start with MDPI drawables and then resize them: the physical size of the drawable will be very close between your computer screen and an MDPI Android device. If you view an HDPI drawable on your computer and on an HDPI device you will notice that it's much bigger (again, physically -- put a ruler on it style) on the PC screen.
  2. If you do not supply special drawables for each density, Android will scale the closest one available automatically.
  3. You should not consider the DPI of a device to have anything to do with screen size and/or number of pixels and/or resolution and/or aspect ratio. A device could be very small and have an HDPI screen or very large and have an LDPI screen. The whole point of this density-differentiation is to have things look the same size on all devices, not fit the same on all devices. For example, if a drawable fills the whole screen on one MDPI device do not expect it to do the same on another MDPI device. Also, do not expect to "see the same thing" on different DPI devices. Most HDPI devices actually have more space than lower DPI devices. For example, if a ListView can show 5 items on a MDPI device it might be able to show 6 items on an HDPI device, in spite of the fact that the ListView items have the same density-independent (i.e. 1.5 times larger on HDPI than on MDPI) height.

我可能有点跑题了,但这些是我通过用头撞到它们而及时学到的东西.只是想拯救别人的头痛:)

I might have gone a bit offtopic, but these are things I have learned in time by banging my head against them. Just trying to save someone else's headache :)

这篇关于解释drawable、drawable-ldpi、drawable-mdpi和drawable-hdpi的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆