gpt4 book ai didi

Android DP 到 PX 的转换,在 mdpi 上 160 dp 总是 160 px 吗?

转载 作者:太空狗 更新时间:2023-10-29 14:13:48 29 4
gpt4 key购买 nike

我在关于 http://developer.android.com/guide/practices/screens_support.html 的一些不幸的歧义中迷失了方向,而且我找不到澄清问题的 stackoverflow 答案。

我很清楚文档声称的内容:

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

问题在于他们在该公式中对“dp”的定义。根据页面下方的图形,mdpi 级设备的“实际密度”似乎跨越了一系列值,从大约 120 到大约 200。这是否意味着 160 dpi 可以映射到 120 到 200 之间的任何位置200 像素用于 mdpi 级设备?还是 mdpi 级设备总是将 160 dpi 转换为 160 像素?

最佳答案

根据 this post from Dianne Hackborn ,确实是这样。 “兼容”Android 设备不能具有非标准密度:

In theory then Android can scale to any density and show its UI to match the exact density of the screen. In practice we don't do this -- we have defined a handful of specific densities we support and require that compatible devices stick to them. Why is this?

The first reason is just to help our developers. UI designers tend to like to make nice clean graphics; these graphics are drawn as bitmaps, and giving designers a small set of target bitmap sizes to support instead of infinite variation makes things a lot simpler for them.

(...)

So Android defines a few major buckets of density values that devices can use, called ldpi (approx 120dpi), mdpi (160 dpi), hdpi (240 dpi), and xhdpi (320 dpi). Manufacturers can select the density that is appropriate for their device, as long as it results in a screen that (after scaling for density) is within the minimum allowed screen size of the platform.

关于Android DP 到 PX 的转换,在 mdpi 上 160 dp 总是 160 px 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24459772/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com