“px"、“dip"、“dp"之间有什么区别?和“sp"? [英] What is the difference between "px", "dip", "dp" and "sp"?

查看:33
本文介绍了“px"、“dip"、“dp"之间有什么区别?和“sp"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 度量单位有什么区别?

  • 像素
  • dp
  • sp

解决方案

来自 Android 开发者文档:

  1. <块引用>

    像素
    >像素 - 对应于屏幕上的实际像素.

  2. <块引用>


    >英寸 - 基于屏幕的物理尺寸.
    >1 英寸 = 2.54 厘米

  3. <块引用>

    毫米
    >毫米 - 基于屏幕的物理尺寸.

  4. <块引用>


    > - 基于屏幕物理尺寸的 1/72 英寸.

  5. <块引用>

    dpdip
    >密度-独立像素- 基于屏幕物理密度的抽象单位.这些单位相对于 160dpi 屏幕,因此 dp 是 160 dpi 屏幕上的一个像素.dp-to-pixel的比例会随着屏幕密度的变化而变化,但不一定成正比.注意:编译器同时接受dip"和dip".和dp",虽然dp"更符合sp".

  6. <块引用>

    sp
    >可缩放像素 OR 与比例无关的像素 - 这就像 dp 单位,但它也按比例缩放用户的字体大小首选项.建议你指定字体大小时使用此单位,因此它们将被调整对于屏幕密度和用户的偏好.请注意,Android 文档与 sp 实际代表的含义不一致,一个 doc 说与比例无关的像素",other 表示可缩放像素".

来自 了解 Android 中的密度独立性:

<头>
密度桶屏幕密度物理尺寸像素大小
ldpi120 dpi0.5 x 0.5 英寸0.5 英寸 * 120 dpi = 60x60 像素
mdpi160 dpi0.5 x 0.5 英寸0.5 英寸 * 160 dpi = 80x80 像素
hdpi240 dpi0.5 x 0.5 英寸0.5 英寸 * 240 dpi = 120x120 像素
xhdpi320 dpi0.5 x 0.5 英寸0.5 英寸 * 320 dpi = 160x160 像素
xxhdpi480 dpi0.5 x 0.5 英寸0.5 英寸 * 480 dpi = 240x240 像素
xxxhdpi640 dpi0.5 x 0.5 英寸0.5 英寸 * 640 dpi = 320x320 像素

<头>
单位说明每物理英寸的单位密度无关?每个屏幕上的物理尺寸都一样吗?
像素像素变化没有没有
英寸1
毫米毫米25.4
pt积分72
dp密度无关像素~160没有
sp缩放独立像素~160没有

还可以在 Google 设计文档中找到更多信息.

What is the difference between Android units of measure?

  • px
  • dip
  • dp
  • sp

解决方案

From the Android Developer Documentation:

  1. px
    > Pixels - corresponds to actual pixels on the screen.

  2. in
    > Inches - based on the physical size of the screen.
    > 1 Inch = 2.54 centimeters

  3. mm
    > Millimeters - based on the physical size of the screen.

  4. pt
    > Points - 1/72 of an inch based on the physical size of the screen.

  5. 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".

  6. 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 what sp 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"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆