PX,DP,倾角和SP在Android上的区别? [英] Difference between px, dp, dip and sp on Android?

查看:169
本文介绍了PX,DP,倾角和SP在Android上的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间有什么区别:


  • 像素


  • DP

  • SP

在Android?


解决方案

的Andr​​oid开发者文档



  1.   

    像素结果
      像素 - 对应于屏幕上的实际像素




  2.   

    结果
      英寸 - 基于屏幕的物理尺寸结果。
      1英寸=2.54厘米




  3.   

    毫米结果
      毫米 - 基于屏幕的物理尺寸




  4.   

    PT 结果
      点 - 1/72英寸基于屏幕的物理尺寸




  5.   

    DP 结果
      密度独立像素 - 即是基于屏幕的物理密度的抽象单元。这些单位是相对于160
          DPI屏幕,所以一个DP是一个160 dpi的屏幕上的一个像素。的比率
          DP到像素将与屏幕密度改变,但不一定
          成正比。注:编译器既接受探底和
          DP,尽管DP是与SP更加一致。




  6.   

    SP 结果
      比例无关像素 - 这是像DP单元,但它也由用户的字体大小preference缩放。它是建议你
          指定字体大小时要使用本机,所以他们将被调整
          两个屏幕密度和用户的preference。



从<一个href=\"https://www.captechconsulting.com/blogs/understanding-density-independence-in-android\">Understanding密度独立在Android中:

  + ---------------- + ---------------- + --- ------------ + ------------------------------- +
|密度铲斗|屏幕像素密度|物理尺寸|像素大小|
+ ---------------- + ---------------- + --------------- ------------------------------- + +
| LDPI | 120 DPI |在0.5×0.5 | 0.5 * 120 dpi的= 60×60像素|
+ ---------------- + ---------------- + --------------- ------------------------------- + +
| MDPI | 160 DPI |在0.5×0.5 | 0.5 * 160 dpi的= 80x80像素|
+ ---------------- + ---------------- + --------------- ------------------------------- + +
|华电国际| 240 DPI |在0.5×0.5 | 0.5 * 240 dpi的= 120×120像素|
+ ---------------- + ---------------- + --------------- ------------------------------- + +
| xhdpi | 320 DPI |在0.5×0.5 | 0.5 * 320 dpi的= 160x160的像素|
+ ---------------- + ---------------- + --------------- ------------------------------- + +
| xxhdpi | 480 DPI |在0.5×0.5 | 0.5 * 480 dpi的= 240x240像素|
+ ---------------- + ---------------- + --------------- ------------------------------- + +
| xxxhdpi | 640 DPI |在0.5×0.5 | 0.5 * 640 dpi的=为320x320像素|
+ ---------------- + ---------------- + --------------- ------------------------------- + +
+ --------- ------------- + + + --------------- --------- ---- + -------------------- +
|单位|说明|个单位|密度|相同的物理尺寸|
| | |物理英寸|独立|在每个屏幕|
+ --------- ------------- + + + --------------- --------- ---- + -------------------- +
| PX |像素|变化|无|无|
+ --------- ------------- + + + --------------- --------- ---- + -------------------- +
|在|英寸| 1 |是|是|
+ --------- ------------- + + + --------------- --------- ---- + -------------------- +
|毫米|毫米| 25.4 |是|是|
+ --------- ------------- + + + --------------- --------- ---- + -------------------- +
| PT |积分| 72 |是|是|
+ --------- ------------- + + + --------------- --------- ---- + -------------------- +
| DP |密度| 〜160 |是|无|
| |独立| | | |
| |像素| | | |
+ --------- ------------- + + + --------------- --------- ---- + -------------------- +
| SP |秤| 〜160 |是|无|
| |独立| | | |
| |像素| | | |
+ --------- ------------- + + + --------------- --------- ---- + -------------------- +

更多信息可以也可以在谷歌设计文件找到。

What is the difference between:

  • px
  • dip
  • dp
  • sp

on Android?

解决方案

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
    Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

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     | 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      |               |             |                    | 
+---------+-------------+---------------+-------------+--------------------+

More info can be also be found in the Google Design Documentation.

这篇关于PX,DP,倾角和SP在Android上的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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