gpt4 book ai didi

android - px、dip、dp和sp有什么区别?

转载 作者:IT老高 更新时间:2023-10-28 12:48:01 27 4
gpt4 key购买 nike

计量单位之间有什么区别px、dip、dp、sp?

最佳答案

来自 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 OR 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 160dpi 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 youuse this unit when specifying font sizes, so they will be adjustedfor 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".

来自 Understanding Density Independence In 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 Design Documentation 中找到。 .

关于android - px、dip、dp和sp有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2025282/

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