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

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

问题描述

Android度量单位有什么区别?

What is the difference between Android units of measure?

  • px
  • dp
  • sp

推荐答案

来自 Android开发人员文档:

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

px
Pixels - corresponds to actual pixels on the screen.


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

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

  • mm
    毫米-根据屏幕的物理尺寸.

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

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

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

  • dp dip
    与密度无关的像素-基于屏幕物理密度的抽象单位.这些单位相对于160 dpi屏幕,因此一个dp是160 dpi屏幕上的一个像素.比例 像素到点的dp会随屏幕密度而变化,但不一定 成正比.注意:编译器接受"dip"和"dip" "dp",尽管"dp"与"sp"更一致.

    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
    缩放独立像素-就像dp单位一样,但是它也通过用户的字体大小首选项进行缩放.推荐你 指定字体大小时使用本机,因此将对其进行调整 屏幕密度和用户偏好都可以.

    sp
    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 user's preference.

  • 来自了解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     | Density     | Same Physical Size | 
    |         |             | Physical Inch | Independent | 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     | ~160          | Yes         | No                 | 
    |         | Independent |               |             |                    | 
    |         | Pixels      |               |             |                    | 
    +---------+-------------+---------------+-------------+--------------------+
    | sp      | Scale       | ~160          | Yes         | No                 | 
    |         | Independent |               |             |                    | 
    |         | Pixels      |               |             |                    | 
    +---------+-------------+---------------+-------------+--------------------+
    

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

    这篇关于"px","dip","dp"和"px"之间有什么区别?和"sp"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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