Android中的尺寸单位

[size=medium]Dimension[/size]
A dimension value defined in XML. A dimension is specified with a number followed by a unit of measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android:

[size=medium]dp[/size]
dp 是与密度无关的像素,基于屏幕密度的抽象单位。在每英寸160个点的屏幕上,1dp与1px大致相等。当运行在更高/更低密度的屏幕上,1dp中的像素数根据屏幕的dpi(dots per inch)数而按比例决定。这个dp与(pixel)像素比例根据屏幕密度而变化。使用dp单位(而不是px单位) 是一个简单的解决方法,使我们的布局能自适应不同的屏幕密度,在不同的设备间能保持一致的展示真实的UI元素的尺寸。
Density-independent Pixels - An abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal to 1px. When running on a higher density screen, the number of pixels used to draw 1dp is scaled up by a factor appropriate for the screen's dpi. Likewise, when on a lower density screen, the number of pixels used for 1dp is scaled down. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Using dp units (instead of px units) is a simple solution to making the view dimensions in your layout resize properly for different screen densities. In other words, it provides consistency for the real-world sizes of your UI elements across different devices.


[size=medium]sp[/size]
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 recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.


[size=medium]pt[/size]
pt,1/72 英寸。
Points - 1/72 of an inch based on the physical size of the screen.

[size=medium]px[/size]
px,像素,屏幕上的真实像素,在真实环境中,使用不同的设备显示时,不建议使用。不同的设备显示效果不同。
Pixels - Corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices; each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen.

mm
Millimeters - Based on the physical size of the screen.
in
Inches - Based on the physical size of the screen.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值