PX,DP,DIP和SP在Android的区别? [英] Difference between px, dp, dip and sp in Android?

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

问题描述

之间的区别是什么:

  • PX
  • DP
  • SP

    在Android的?

解决方案
  • PX 是一个像素。
  • SP 是独立的规模像素。
  • 是密度无关的像素。

  + ---------------- + ---------------- + --- ------------ + ------------------------------- +
|密度桶|屏幕显示|物理尺寸|像素大小|
+ ---------------- + ---------------- + --------------- + ------------------------------- +
| LDPI | 120 DPI | 0.5×0.5 |在* 120 DPI = 60×60像素0.5 |
+ ---------------- + ---------------- + --------------- + ------------------------------- +
| MDPI | 160 DPI | 0.5×0.5 |在* 160 dpi的= 80×80像素0.5 |
+ ---------------- + ---------------- + --------------- + ------------------------------- +
|华电国际| 240 DPI | 0.5×0.5 |在* 240 dpi的= 120×120像素0.5 |
+ ---------------- + ---------------- + --------------- + ------------------------------- +
| xhdpi | 320 DPI | 0.5×0.5 |在* 320 dpi的= 160x160的像素0.5 |
+ ---------------- + ---------------- + --------------- + ------------------------------- +
| xxhdpi | 480 DPI | 0.5×0.5 |在* 480 dpi的= 240x240像素0.5 |
+ ---------------- + ---------------- + --------------- + ------------------------------- +
| xxxhdpi | 640 DPI | 0.5×0.5 |在* 640 dpi的=最高320x320像素0.5 |
+ ---------------- + ---------------- + --------------- + ------------------------------- +  

您会使用

  • SP 的字体大小
  • 的一切,其中浸== DP

Android开发者中心

  + --------- + ------------- + ------------- -  + ------------- + -------------------- +
|密度|说明|个单位|密度|相同的物理尺寸|
| | |物理英寸|独立|在每个屏幕|
+ --------- + ------------- + -------- + --------- ---- + -------------------- +
| PX |像素|变化|没有|没有|
+ --------- + ------------- + -------- + --------- ---- + -------------------- +
|在|英寸| 1 |是|是|
+ --------- + ------------- + -------- + --------- ---- + -------------------- +
|毫米|毫米| 25.4 |是|是|
+ --------- + ------------- + -------- + --------- ---- + -------------------- +
| PT |点| 72 |是|是|
+ --------- + ------------- + -------- + --------- ---- + -------------------- +
| DP |密度| 〜160 |是|没有|
| |独立| | | |
| |像素| | | |
+ --------- + ------------- + -------- + --------- ---- + -------------------- +
| SP |秤| 〜160 |是|没有|
| |独立| | | |
| |像素| | | |
+ --------- + ------------- + -------- + --------- ---- + -------------------- +  

     

PX
  像素 - 对应于屏幕上实际像素

     


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

     

毫米
  毫米 - 基于所述屏幕的物理尺寸

     

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

     

DP
  密度无关像素 - 即是基于屏幕的物理密度的抽象单元。这些单位是相对于160 dpi的屏幕上,所以一个DP为160 dpi的屏幕上的一个像素。 DP到像素的比例将与屏幕密度变化,但不直接比例一定。注:编译器既接受探底和DP,虽然DP是SP更一致

     

SP
  规模无关的像素 - 这就像DP单位,但它也缩小了用户的字体大小preference。这是建议,指定的字体大小,当您使用本机,所以他们将被调整为屏幕的密度和用户的preference。

What is the difference between :

  • px
  • dip
  • dp
  • sp

    in Android?

解决方案

  • px is one pixel.
  • sp is scale-independent pixels.
  • dip is Density-independent pixels.

+----------------+----------------+---------------+-------------------------------+
| Density Bucket | Screen Display | 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 | 
+----------------+----------------+---------------+-------------------------------+

You would use

  • sp for font sizes
  • dip for everything else, where dip == dp

From Android Developers center:

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

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

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

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