简体   繁体   English

解释drawable,drawable-ldpi,drawable-mdpi和drawable-hdpi之间的区别

[英]Explain the difference between drawable, drawable-ldpi, drawable-mdpi and 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. 我对每个目录的用途都有一个大概的了解,但是我对这个概念并不十分清楚,我有一些具体的问题。

For example, what are the target DPIs for each directory? 例如,每个目录的目标DPI是什么? When you create an asset, should it be at that target DPI or should it be at the more normal 72dpi screen DPI? 创建资产时,应将其设置为该目标DPI还是将其设置为更普通的72dpi屏幕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? 如果您要针对多个设备,是否应该将PNG放在可绘制的图像中,还是应该始终针对特定屏幕量身定制多个版本?

Thanks. 谢谢。

As the others have suggested, the Android online documentation has great articles on this. 正如其他人所建议的那样,Android在线文档对此有很多文章。 However, I'm going to try and list here some quick and helpful tips: 但是,我将尝试在此处列出一些快速且有用的提示:

  1. Consider MDPI is 1 . 考虑MDPI为1 Then, LDPI is 0.75 and HDPI is 1.5 . 然后,LDPI为0.75 ,HDPI为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 (ie 2cm if you put a ruler on the screen). 这也就意味着,如果你有一个可绘制的是,比如说, 50x50一MDPI屏幕上它必须是~37x37一LDPI屏幕上和75x75一个HDPI屏幕上, 以出现在每个大致相同的物理尺寸屏幕(如果在屏幕上放了标尺,则为2厘米)。 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. 另外,您的计算机屏幕很可能是 MDPI,这就是为什么建议先从MDPI可绘制对象开始,然后调整它们的大小的原因:可绘制对象的物理尺寸在计算机屏幕和MDPI Android设备之间非常接近。 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. 如果您在计算机上和HDPI设备上查看华电国际绘制你会发现,它的更大 -在PC屏幕上(同样, 身体放一把尺子上的风格)。
  2. If you do not supply special drawables for each density, Android will scale the closest one available automatically. 如果您没有为每种密度提供特殊的可绘制对象,Android将自动缩放最接近的可用对象。
  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. 您不应该认为设备的DPI与屏幕大小和/或像素数和/或分辨率和/或纵横比有关。 A device could be very small and have an HDPI screen or very large and have an LDPI screen. 设备可能非常小且具有HDPI屏幕,或者非常大且具有LDPI屏幕。 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. 例如,如果可绘制对象填充在一台MDPI设备上的整个屏幕,则不要指望它在另一台MDPI设备上执行相同的操作。 Also, do not expect to "see the same thing" on different DPI devices. 另外,不要期望在不同的DPI设备上“看到相同的东西”。 Most HDPI devices actually have more space than lower DPI devices. 实际上,大多数HDPI设备比低DPI设备具有更多的空间。 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 (ie 1.5 times larger on HDPI than on MDPI) height. 例如,如果ListView项可以在MDPI设备上显示5个项目,则尽管ListView项具有相同的密度无关性(即,HDPI上的密度是HDPI的1.5倍),但它可能能够在HDPI设备上显示6个项目。在MDPI上)的高度。

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 :) 只是想挽救别人的头痛:)

Sorry but Android has a great online doc with examples so for this type of question the answer is: 抱歉,Android有很多在线示例文档,因此对于此类问题,答案为:

http://developer.android.com/guide/practices/screens_support.html http://developer.android.com/guide/practices/screens_support.html

There are no exact DPI values for each folder. 每个文件夹没有确切的DPI值。 Every folder is related to some range. 每个文件夹都与某个范围相关。 See here: http://developer.android.com/guide/practices/screens_support.html 参见此处: http : //developer.android.com/guide/practices/screens_support.html

These directories must hold drawable resources optimized for some screen density. 这些目录必须包含为某些屏幕密度优化的可绘制资源。 You can hold just one drawable for HDPI or any other, but on devices with other DPI settings image will be resized somehow and it will take time/resources. 您只能为HDPI或其他任何对象保留一个可绘制对象,但是在具有其他DPI设置的设备上,图像会以某种方式调整大小,这将花费时间/资源。 Also low DPI image will look poor on devices with HDPI. 同样,在具有HDPI的设备上,低DPI图像看起来也不佳。

Due to different screen size and resolutions, Android lets you arrange your drawable images according to folders. 由于屏幕尺寸和分辨率不同,Android允许您根据文件夹排列可绘制图像。 Images for high dpi displays should be placed in hdpi and similarly mdpi and ldpi. 用于高dpi显示的图像应放置在hdpi中,并且类似地放置在mdpi和ldpi中。 The default folder for the drawables is drawables if the operating system does not match any dpi category or the resources is not found in special dpi directories the system picks the resource from the drawables directory. 如果操作系统与任何dpi类别都不匹配,或者在特殊dpi目录中找不到资源,则drawables的默认文件夹是drawables,系统会从drawables目录中选择资源。

The size are not exact but upto 130dpi it is considered small, from 130 to 180 it can be considered mdpi, from 180 to 200 it can be considered as hdpi and the higher is classified as xdpi. 尺寸不精确,但最高为130dpi时,它被认为是很小的;从130到180时,它可以被认为是mdpi;从180到200时,它可以被认为是hdpi,而较高者则被分类为xdpi。

http://developer.android.com/guide/practices/screens_support.html http://developer.android.com/guide/practices/screens_support.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM