找回密码
 立即注册
密度densitythe160 | android开发 2022-11-03 33 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
Android中的长度单位详解(dp、sp、px、in、pt、mm)看到有很多人不太理解dp、sp和px的区别:现在这儿介绍一下dp和sp。dp也就是dip。这个和sp基本类似。假如设置表示长度、高度等属性时可以使用dp或sp。但假如设置字体,需求使用sp。dp是与密度无关,sp除了与密度无关外,还与scale无关。假如屏幕密度为160,这时dp和sp和px是相同的。1dp=1sp=1px,但假如使用px作单位,假如屏幕大小不变(假设仍是3.2寸),而屏幕密度变成了320。那么本来TextView的宽度设成160px,在密度为320的3.2寸屏幕里看要比在密度为160的3.2寸屏幕上看短了一半。但假如设置成160dp或160sp的话。系统会自动将width属性值设置成320px的。也就是160
320/160。其间320/160可称为密度份额因子。也就是说,假如使用dp和sp,系统会依据屏幕密度的变化自动进行转换。

(In the details of length units in Android (dp, sp, px, in, pt, mm), we can see that many people do not understand the difference between dp, sp and px. Now let's introduce dp and sp. Dp is also called dip. This is basically similar to sp. If you can use dp or sp when setting attributes such as length and height. But if you set the font, you need to use sp. Dp is density independent, sp is not only density independent, but also scale independent. If the screen density is 160, then dp, sp and px are the same. 1dp=1sp=1px, but if you use px as the unit, if the screen size remains unchanged (assuming it is still 3.2 inches), the screen density becomes 320. Then the width of TextView is originally set to 160px, which is half shorter on a 3.2 inch screen with a density of 320 than on a 3.2 inch screen with a density of 160. But if it is set to 160dp or 160sp. The system will automatically set the width attribute value to 320px. That is 160
320/160。 320/160 can be called density share factor. That is, if you use dp and sp, the system will automatically convert according to the change of screen density.)

[下载]09341375052.rar




上一篇:android常用的系统调用
下一篇:Android RSS阅读器的源码