当前位置:网站首页>andorid系统layout、values、drawable适配
andorid系统layout、values、drawable适配
2022-07-28 17:34:00 【Alex_designer】
andorid屏幕适配
| 密度类型 | 代表的分辨率(px) | 屏幕密度(dpi) | 换算(px/dp) | 比例 |
|---|---|---|---|---|
| 低密度(ldpi) | 240x320 | 120 | 1dp=0.75px | 3 |
| 中密度(mdpi) | 320x480 | 160 | 1dp=1px | 4 |
| 高密度(hdpi) | 480x800 | 240 | 1dp=1.5px | 6 |
| 超高密度(xhdpi) | 720x1280 | 320 | 1dp=2px | 8 |
| 超超高密度(xxhdpi) | 1080x1920 | 480 | 1dp=3px | 12 |
在Android中,规定以160dpi(即屏幕分辨率为320x480)为基准:1dp=1px
首选smallestWidth
smallestWidth 限定符适配
- 屏幕分辨率限定符适配是根据屏幕分辨率的,Android 设备分辨率一大堆,而且还要考虑虚拟键盘,这样就需要大量的 dimens.xml 文件。因为无论手机屏幕的像素多少,密度多少,90% 的手机的最小宽度都为 360dp,所以采用 smallestWidth 限定符适配只需要少量 dimens.xml 文件即可。
- 屏幕分辨率限定符适配采用的是 px 单位,而 smallestWidth 限定符适配采用的单位是 dp 和 sp,dp 和 sp 是 google 推荐使用的计量单位。又由于很多应用要求字体大小随系统改变,所以字体单位使用 sp 也更灵活。
- 屏幕分辨率限定符适配需要设备分辨率与 values-xx 文件夹完全匹配才能达到适配,而 smallestWidth 限定符适配寻找 dimens.xml 文件的原理是从大往小找,例如设备的最小宽度为 360dp,就会先去找 values-360dp,发现没有则会向下找 values-320dp,如果还是没有才找默认的 values 下的 demens.xml 文件,所以即使没有完全匹配也能达到不错的适配效果。
- 无论是宽度还是高度,哪一边小就认为哪一边是“最小宽度”
- 限定符类型:
- 尺寸(size)限定符
- 最小宽度(Smallest-width)限定符
- 布局别名
- 屏幕方向(Orientation)限定符
宽高限定符适配 这种做法不推荐使用, 比如1920x1080的手机就一定要找到1920x1080的限定符,否则就只能用统一的默认的dimens文件了。而使用默认的尺寸的话,UI就很可能变形,简单说,就是容错机制很差。
1.layout-sw500dp
这里的sw代表smallwidth的意思,当你的屏幕的绝对宽度大于500dp时,屏幕就会自动调用layout-sw500dp文件夹里面的布局。
注意:这里的绝对宽度是指手机的实际宽度,与手机横竖屏无关。
2.layout-w500dp
当你的屏幕的相对宽度大于500dp时,屏幕就会自动调用layout-w500dp文件夹里面的布局。
注意:这里的相对宽度是指手机相对放置的宽度;即当手机竖屏时,为较小边的长度;当手机横屏时,为较长边的长度。
3.layout-h500dp
与layout-w500dp的使用一样,只是这里指的是相对的高度。
注意:这里的相对高度是指手机相对放置的高度;即当手机竖屏时,为较长边的长度;当手机横屏时,为较小边的长度。但这种方式很少使用,因为屏幕在相对高度上,即在纵向上通常能够滚动导致长度变化,而不像横向那样基本固定,因而这个方法灵活性差,google官方文档建议尽量使用这种方式。
实例:密度为240 尺寸为:1280x720和1920x1080 应该放在哪个适配文件夹下
Android中,规定以160dpi(即屏幕分辨率为320x480)为基准
对应的密度比为:
160 1
240 1.5
320 2
用最小做为宽度:1280x720 是720,1920x1080是1080
720/1.5 =480
1080/1.5 =720
sw480dp
sw720dp
layout 就是layout-sw720dp , 是values 就是values-sw720dp
参考:
边栏推荐
- RFs self study notes (II): theoretical measurement model - without clutter but with detection probability
- 文章翻译软件-批量免费翻译软件支持各大翻译接口
- 这种动态规划你见过吗——状态机动态规划之股票问题(下)
- 英语文章翻译-英语文章翻译软件-免费批量翻译
- Application of time series database in bridge monitoring field
- Application of time series database in museum environment detection
- 剑指 Offer II 109. 开密码锁
- As for the white box test, you have to be skillful in these skills~
- Jestson nano Object detection
- C语言循环语句强化练习题
猜你喜欢

Transformer for anomaly detection - instra "painting transformer for anomaly detection"

It is the best tool to evaluate six kinds of map visualization software in three categories

Sword finger offer II 109. unlock the password lock

Application of time series database in bridge monitoring field

Libgdx learning road 02: draw game map with tiled

Rust 入门指南(rustup, cargo)

Application of time series database in museum environment detection

ES6's new data container map

About ASM redundancy

Tikz draw Gantt chart in FJSP -trans necessary
随机推荐
JS preventDefault() 键盘输入限制 onmousewheel stopPropagation停止事件传播
Update of objects in ES6
第一次写博客
剑指 Offer II 109. 开密码锁
Application of time series database in cigarette factory
Self-adaptive multi-objective evolutionary algorithm for flexible job shop scheduling with fuzzy pro
智能合约安全——溢出漏洞
2022年中总结
SaltStack进阶
Ardupilot software in the loop simulation and online debugging
Prometheus部署
C language cycle sentence strengthening exercises
ardupilot软件在环仿真与在线调试
机器学习 --- 模型评估、选择与验证
Adobe XD web design tutorial
New functions of ES6 string
Mid 2022 summary
Cvpr19 - adjust reference dry goods bag of tricks for image classification with revolutionary neural network
【笔记】《结网:互联网产品经理改变世界》
ES6 conversion of new data type set and arr set map