android - dip、px、dpi的关系

标签 android layout resolution

如果在布局 xml 文件中,我将大小设置为,例如 12dip。在 mdpi 中总是 12px 而在 hdpi 中总是 18px 吗?

那么对于 mdpi 来说 dip 总是正确的并且对于其他密度会相应地缩放吗?

最佳答案

official documentation 完全涵盖了这个问题. this 涵盖了 dip、px 和 dpi 之间的关系部分。

引用:

Density-independent pixel (dp)

A virtual pixel unit that applications can use in defining their UI, to express layout dimensions or position in a density-independent way.

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dp units needed, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: pixels = dps * (density / 160). For example, on 240 dpi screen, 1 dp would equal 1.5 physical pixels. Using dp units to define your application's UI is highly recommended, as a way of ensuring proper display of your UI on different screens.

所以声明:

that always be 12px in mdpi and so 18px in hdpi

根据文档,似乎是正确的。

关于android - dip、px、dpi的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4517289/

相关文章:

android - 在 values\attrs.xml 中声明属性时出错

javascript - Liquid Layout, JS 解决方案

php - 将页面包含到 index.php 或创建页面的顶部和底部并包含到所有内容页面?

html - 使网站适合不同的分辨率

C# 方法解析,long 与 int

android - supportInvalidateOptionsMenu() 是否有效?

android - 文本未显示在 MapView 叠加层上

JavaFX布局: all in Grid vs Separator for each cell

c++ - DirectX 拉伸(stretch)像素

java - 关于新对象