简体   繁体   English

了解android布局和可绘制资源

[英]Understanding android layout and drawable resources

I have read many articles, documentations, tutorials but I am still confused about how android uses layouts and drawable. 我已经阅读了很多文章,文档,教程,但我仍然对android如何使用布局和drawable感到困惑。

Please correct me if I am wrong ! 如果我错了请纠正我!

I know DPI stand for (density independent pixel) dp == dpi (no difference). 我知道DPI代表(密度无关像素)dp == dpi(没有区别)。 So, that means if two devices with same size but different densities will produce the same object size (ex. ImageView) but in different quality? 那么,这意味着如果两个具有相同大小但密度不同的设备将产生相同的对象大小(例如ImageView)但质量不同?

在此输入图像描述

If I am right, that means if I have an image, I should put the picture with the highest quality in res/ldpi, and the other picture with lowest quality in res/mdpi folder? 如果我是对的,这意味着如果我有一个图像,我应该把res / ldpi中最高质量的图片和res / mdpi文件夹中质量最低的另一张图片放在一起? What is the difference between images that are in res/mdpi and res/hdpi? res / mdpi和res / hdpi中的图像有什么区别? Sizes, quality or what? 尺寸,质量还是什么?

Let's say you have an image and want to display it the same size regardless of your device dpi. 假设您有一个图像,并希望无论您的设备dpi如何都显示相同的大小。 Then you use dp to ensure this. 然后你使用dp来确保这一点。 Since the size is the same, let's say 1 cm, in the low dpi device there will be less pixels in that cm, let's say 160, thus a lower resolution image will be enough. 由于尺寸相同,比如1厘米,在低dpi设备中,该cm中的像素将更少,比方说160,因此分辨率较低的图像就足够了。 In particular a 160x160 pixel image will be the right size. 特别是160x160像素的图像尺寸合适。

In a higher dpi device, eg with 200 pixels per cm, you will need a higher resolution version, or better you can use a higher resolution image, for example a 200x200 one. 在更高的dpi设备中,例如每厘米200像素,您将需要更高分辨率的版本,或者更好的是您可以使用更高分辨率的图像,例如200x200的图像。

They will still e the same size, but the one in the hdpi device will have more details. 它们仍然具有相同的尺寸,但hdpi设备中的那个将具有更多细节。

Here you find the ratios you should consider when resizing your images (many tools can do this automatically): 在这里,您可以找到调整图像大小时应考虑的比率(许多工具可以自动执行此操作):

http://developer.android.com/training/basics/supporting-devices/screens.html http://developer.android.com/training/basics/supporting-devices/screens.html

The logical density of the display. 显示器的逻辑密度。 This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), providing the baseline of the system's display. 这是密度独立像素单元的缩放因子,其中一个DIP是大约160dpi屏幕上的一个像素(例如240x320,1.5“x2”屏幕),提供系统显示的基线。 Thus on a 160dpi screen this density value will be 1; 因此,在160dpi屏幕上,此密度值将为1; on a 120 dpi screen it would be .75; 在120 dpi的屏幕上它将是.75; etc. 等等

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

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