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

查看:385
本文介绍了解释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置于可绘制状态,还是应该始终针对特定屏幕量身定制多个版本?

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.这意味着如果您在MDPI屏幕上具有50x50的可绘制对象,则它必须在LDPI屏幕上为~37x37,在HDPI屏幕上为75x75才能显示每个屏幕上的物理尺寸大致相同(即,如果在屏幕上放上标尺,则为2厘米).另外,您的计算机屏幕上最可能是 MDPI,因此建议您先从MDPI可绘制对象开始,然后再调整它们的大小:可绘制对象的物理尺寸会非常接近您的计算机屏幕和MDPI Android设备.如果您在计算机和HDPI设备上查看可绘制的HDPI,您会注意到它的尺寸(再次,物理上 –在其样式上放置了标尺). PC屏幕.
  2. 如果您没有为每种密度提供特殊的可绘制图形,则Android会自动缩放最接近的可用图形.
  3. 您不应认为设备的DPI与屏幕尺寸和/或像素数和/或分辨率和/或宽高比有关.设备可能非常小且具有HDPI屏幕,或者非常大且具有LDPI屏幕.这种密度差异的全部目的是使所有设备上的东西看起来相同适合所有设备.例如,如果可绘制对象填充在一台MDPI设备上的整个屏幕,则不要指望它在另一台MDPI设备上执行相同的操作.另外,不要期望在不同的DPI设备上看到相同的东西".实际上,大多数HDPI设备比低DPI设备具有更大的空间.例如,如果ListView项可以在MDPI设备上显示5个项目,则尽管ListView项具有相同的密度无关性(即1.5倍),但它可能能够在HDPI设备上显示6个项目. HDPI上的尺寸要比MDPI上的尺寸高).
  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天全站免登陆