简体   繁体   English

我们应该使用准确的DPI号码来实现多种屏幕尺寸吗?

[英]Should we use the exactly DPI number to implement for multiple screen size?

I know we have some standard of DPI that we can use it for support multiple screen size in an like : 我知道我们有一些DPI标准,我们可以用它来支持多种屏幕尺寸:

ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi

But when I calculate for some real device, eg LG G3 - it has DPI is 538. 但是当我计算一些真实设备时,例如LG G3 - 它的DPI是538。

So my question is do we need to use that exactly DPI number for scale the image,... or just let it be one of xxhdpi ( 480dpi ) or xxxhdpi ( 640dpi ). 所以我的问题是我们需要使用的正是DPI数量规模的形象,...,还是让它成为xxhdpi(480dpi)xxxhdpi之一(640dpi)。

For my opinion, I think you shouldn't care about information dpi of devices. 对于我的看法,我认为你不应该关心设备的信息dpi。 You should only focus to provide images, size (dp,sp) etc for some type of screens : 您应该只关注某些类型的屏幕提供图像,大小(dp,sp)等:

ldpi (low) ~120dpi

mdpi (medium) ~160dpi

hdpi (high) ~240dpi

xhdpi (extra-high) ~320dpi

xxhdpi (extra-extra-high) ~480dpi

xxxhdpi (extra-extra-extra-high) ~640dpi

========================================================================= Example: As you maybe known that 1 px = dp (dpi/160) ================================================== =======================示例:您可能知道1 px = dp(dpi / 160)

So if you have an image with size is 32 x 32 px on screen 160 dpi. 因此,如果您的图像大小为32 x 32 px,屏幕160 dpi。 It's mean your image get size 32 x 32 dp. 这意味着你的图像大小为32 x 32 dp。

Now you want to scale it on xxhdpi (extra-extra-high) ~480dpi. 现在你想在xxhdpi(extra-extra-high)~480dpi上进行缩放。

On xxhdpi (extra-extra-high) ~480dpi : 1 px = dp(480/160) = 3dp 在xxhdpi(extra-extra-high)~480dpi:1 px = dp(480/160)= 3dp

Then you only need to provide another image with size 32*3 x 32*3 px = 96 x 96 px 然后,您只需要提供尺寸为32 * 3 x 32 * 3像素= 96 x 96像素的另一幅图像

You just have to provide the right assets and android will take care of the rest. 你只需要提供正确的资产,android将负责其余的事情。 You can check the documentation for more details. 您可以查看文档以获取更多详细信息。

The Android system helps your application achieve density independence in two ways: Android系统通过两种方式帮助您的应用程序实现密度独立性:

  1. The system scales dp units as appropriate for the current screen density 系统根据当前屏幕密度调整dp单位
  2. The system scales drawable resources to the appropriate size, based on the current screen density, if necessary 如有必要,系统会根据当前屏幕密度将可绘制资源缩放到适当的大小

So in your case its better to provide both the assets. 所以在你的情况下,最好提供两种资产。 At runtime, the system uses the appropriate resources for your application, based on the generalized size or density of the current device screen. 在运行时,系统会根据当前设备屏幕的通用大小或密度,为您的应用程序使用适当的资源。

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

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