为什么各种密度提供了多个可绘制?多个、密度

2023-09-07 12:54:20 作者:★n1苏凡

我的应用程序支持从LDPI不同的屏幕密度来xhdpi。它包含一些可绘制(图像)需要在所有密度正常显示。 我想知道的可绘制了许多不同的分辨率如何实际需要提供,考虑到Android的运行时缩放资源时,它无法找到一个为合适的密度。

My app supports various screen densities from ldpi to xhdpi. It contains some drawables (images) that need to be displayed properly on all densities. I'm wondering how many various resolutions of the drawables are actually necessary to provide, considering that Android runtime is scaling resources when it cannot find one for the appropriate density.

如果你只提供MDPI可绘,他们将扩大规模,在华电国际/ xhdpi(模糊)和按比例缩小的LDPI屏幕。

If you provide only mdpi drawables, they will be scaled up on hdpi/xhdpi (blurry) and scaled down on ldpi screen.

不过,如果你只提供xhdi资源,那么他们将在所有密度较低的屏幕缩小。缩减并不能让他们模糊,他们会看起来很好。

However, if you provide only xhdi resources, then they will be scaled down on all lower density screens. Scaling down doesn't make them blurry and they will look fine.

那么为什么还要提供可绘其它密度比xhdpi?

So why bother providing drawables for other densities than xhdpi?

推荐答案

有几个原因使用prescaled可绘制:

There are several reasons to used prescaled drawables:

缩小到较低的分辨率需要的资源(CPU时间,内存和它消耗你的电池更快),特别是如果你有大量的图片,这可能是不需要的。

Scaling down to lower resolutions takes resources (CPU time, memory and it drains your battery faster), especially if you have a lot of images this might be undesired.

缩小大图像可能会导致比使用'pre-调整'更小的图像质量差。特别是如果你的图片是基于矢量原创。或者,它们含有非常细的线条还是细节,这将让时,由于缩放丢失。 例如: 成为 请参见此处这些图像和更多信息的来源在缩放文物。

Scaling down a large image might result in worse quality than using a 'pre-tuned' smaller image. Especially if your images are based on a vector original. Or they contain very fine lines or details, which will get lost when due to the scaling. For example: becomes See here for the source of these images and more information on scaling artifacts.

在较低分辨率图像的像素较大(或图像变小),所以它可能需要去除图​​像的某些方面,以保持它明确/无可厚非的。

On lower resolutions the image pixels are larger (or the image gets smaller), so it might be required to remove certain aspects of the image to keep it clear/understandable.