Android中的尺寸单位 博客分类: android androidui
程序员文章站
2024-03-06 18:05:08
...
Dimension
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:
dp
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.
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 recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.
pt
pt,1/72 英寸。
Points - 1/72 of an inch based on the physical size of the screen.
px
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.
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:
dp
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.
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 recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.
pt
pt,1/72 英寸。
Points - 1/72 of an inch based on the physical size of the screen.
px
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.
推荐阅读
-
Android中的尺寸单位 博客分类: android androidui
-
【辅助工具】20款优秀的移动产品原型和线框图设计工具 博客分类: android
-
Android ViewGroup系列控件的使用 博客分类: javaandroid
-
【辅助工具】20款优秀的移动产品原型和线框图设计工具 博客分类: android
-
开放的谷歌Android让iPhone诺基亚高度紧张(转) 博客分类: IT资讯 AndroidSymbianNokiaMTK中国移动
-
珍藏多年的免费资源第二轮共享:大量android资源 博客分类: 书籍,android android书籍
-
android视频开发 博客分类: IT下的即时通讯嵌入式与语音视频系统 中国移动互联网
-
achartengine在Android中ScrollView组件无法显示的问题 博客分类: 移动开发 中国移动achartengineandroidjavaap
-
android 应用的安装过程 博客分类: android相关
-
android工程下的文件资源类型(转载) 博客分类: android相关 AndroidXMLCSSUIBlog