【Android】dip、dp、sp、pt和px的区别
根据 google 的建议,TextView 的字号最好使用 sp 做单位,而且查看TextView的源码可知Android默认使用sp作为字号单位。将dip作为其他元素的单位。 sp: scaled pixels(放大像素). 主要用于字体显示best for textsize。 mm(毫米):长度单位。
发布日期:2021-06-29 20:54:54
浏览次数:2
分类:技术文章
本文共 3407 字,大约阅读时间需要 11 分钟。
转载自:
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:dpDensity-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.spScale-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.ptPoints - 1/72 of an inch based on the physical size of the screen.pxPixels - 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.mmMillimeters - Based on the physical size of the screen.inInches - Based on the physical size of the screen.
转载地址:https://dengjin.blog.csdn.net/article/details/41692937 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月29日 07时55分14秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
移植Qt4.7.3
2019-04-30
Qt移植对USB鼠标键盘、触摸屏的支持
2019-04-30
LCD驱动移植
2019-04-30
驱动开发小结
2019-04-30
Qt Creator创建纯C、c++工程
2019-04-30
Android单元测试之 Robolectric3.0+
2019-04-30
qt configure参数解释
2019-04-30
Git Push 避免用户名和密码方法
2019-04-30
Java总结篇系列:Java多线程(一)
2019-04-30
产品设计开发要领
2019-04-30
Android线程操作类(暂停、重新开启、停止)
2019-04-30
android - JNI - 一维数组、二维数组的访问与使用
2019-04-30
在 Android Studio 2.2 中愉快地使用 C/C++
2019-04-30
C++和JNI的数据转换
2019-04-30
JNI 传递结构体参数
2019-04-30
JNI中枚举类型作为参数
2019-04-30
qlineedit tab焦点处无法输入问题
2019-04-30
android精确绘制文字位置的方法
2019-04-30
Android中UI线程与后台线程交互设计的5种方法
2019-04-30
[Android]调用字符串资源的几种方法
2019-04-30