What is the difference between quot;pxquot;, quot;dipquot;, quot;dpquot; and quot;spquot;?(“px、“dip、“dp有什么区别?和“sp?)
问题描述
Android 计量单位有什么区别?
- 像素
- 浸
- dp
- sp
来自Android 开发者文档:
- <块引用>
像素
>像素 - 对应于屏幕上的实际像素. - <块引用>
在
>英寸 - 基于屏幕的物理尺寸.
>1 英寸 = 2.54 厘米 - <块引用>
mm
>毫米 - 基于屏幕的物理尺寸. - <块引用>
pt
>点 - 基于屏幕物理尺寸的 1/72 英寸. - <块引用>
dp 或 dip
>密度-独立像素 - 基于屏幕物理密度的抽象单位.这些单位是相对于 160dpi 屏幕,所以 1 dp 是 160 dpi 屏幕上的一个像素.dp与像素的比例会随着屏幕密度而变化,但不一定成正比.注意:编译器同时接受dip".和dp",尽管dp"与sp"更一致. - <块引用>
sp
>可缩放像素 OR 与缩放无关的像素 - 这类似于 dp 单位,但它也按比例缩放用户的字体大小偏好.建议你指定字体大小时使用此单位,因此它们将被调整对于屏幕密度和用户的偏好.请注意,Android 文档与sp
实际代表的含义不一致,一个 doc 说与比例无关的像素",其他表示可缩放像素".
来自 了解 Android 中的密度独立性一个>:
密度桶 | 屏幕密度 | 物理尺寸 | 像素大小 |
---|---|---|---|
ldpi | 120 dpi | 0.5 x 0.5 英寸 | 0.5 英寸 * 120 dpi = 60x60 像素 |
mdpi | 160 dpi | 0.5 x 0.5 英寸 | 0.5 英寸 * 160 dpi = 80x80 像素 |
hdpi | 240 dpi | 0.5 x 0.5 英寸 | 0.5 英寸 * 240 dpi = 120x120 像素 |
xhdpi | 320 dpi | 0.5 x 0.5 英寸 | 0.5 英寸 * 320 dpi = 160x160 像素 |
xxhdpi | 480 dpi | 0.5 x 0.5 英寸 | 0.5 英寸 * 480 dpi = 240x240 像素 |
xxxhdpi | 640 dpi | 0.5 x 0.5 英寸 | 0.5 英寸 * 640 dpi = 320x320 像素 |
单位 | 说明 | 每物理英寸单位数 | 密度无关? | 每个屏幕的物理尺寸都一样? |
---|---|---|---|---|
像素 | 像素 | 变化 | 没有 | 没有 |
在 | 英寸 | 1 | 是的 | 是的 |
mm | 毫米 | 25.4 | 是的 | 是的 |
点 | 积分 | 72 | 是的 | 是的 |
dp | 与密度无关的像素 | ~160 | 是的 | 没有 |
sp | 缩放独立像素 | ~160 | 是的 | 没有 |
还可以在 Google 设计文档中找到更多信息.
What is the difference between Android units of measure?
- px
- dip
- dp
- sp
From the Android Developer Documentation:
-
px
> Pixels - corresponds to actual pixels on the screen. -
in
> Inches - based on the physical size of the screen.
> 1 Inch = 2.54 centimeters -
mm
> Millimeters - based on the physical size of the screen. -
pt
> Points - 1/72 of an inch based on the physical size of the screen. -
dp or dip
> Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp". -
sp
> Scaleable Pixels OR scale-independent pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommended you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference. Note, the Android documentation is inconsistent on whatsp
actually stands for, one doc says "scale-independent pixels", the other says "scaleable pixels".
From Understanding Density Independence In Android:
Density Bucket | Screen Density | Physical Size | Pixel Size |
---|---|---|---|
ldpi | 120 dpi | 0.5 x 0.5 in | 0.5 in * 120 dpi = 60x60 px |
mdpi | 160 dpi | 0.5 x 0.5 in | 0.5 in * 160 dpi = 80x80 px |
hdpi | 240 dpi | 0.5 x 0.5 in | 0.5 in * 240 dpi = 120x120 px |
xhdpi | 320 dpi | 0.5 x 0.5 in | 0.5 in * 320 dpi = 160x160 px |
xxhdpi | 480 dpi | 0.5 x 0.5 in | 0.5 in * 480 dpi = 240x240 px |
xxxhdpi | 640 dpi | 0.5 x 0.5 in | 0.5 in * 640 dpi = 320x320 px |
Unit | Description | Units Per Physical Inch | Density Independent? | Same Physical Size On Every Screen? |
---|---|---|---|---|
px | Pixels | Varies | No | No |
in | Inches | 1 | Yes | Yes |
mm | Millimeters | 25.4 | Yes | Yes |
pt | Points | 72 | Yes | Yes |
dp | Density Independent Pixels | ~160 | Yes | No |
sp | Scale Independent Pixels | ~160 | Yes | No |
More info can be also be found in the Google Design Documentation.
这篇关于“px"、“dip"、“dp"有什么区别?和“sp"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“px"、“dip"、“dp"有什么区别?和“sp"?


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01