采用最小宽度适配方式计算各分辨率下的尺寸大小,参考:https://mp.weixin.qq.com/s/X-aL2vb4uEhqnLzU5wjc4Q
由于px = dp(dpi/160),
所以dp = px/(dpi/160)。
//dp = 160 作为基准尺寸的倍数关系
Reslution dpi pixel ratio
xxxhdpi 640 4
xxhdpi 480 3
xhdpi 320 2
hdpi 240 1.5
mdpi 160 1
UI设计尺寸:750 x 1334 , dpi = 320 , screenWidthDp = 750/(320/160) = 375,以此UI设计尺寸作为基准。
基准:1dp = 1dp = 2px
dpi = 320 --> 1dp = 1 * (375 / 375) = 1dp
dpi = 480 --> 1dp = 1 * (480 / 375) = 1.28dp
dpi = 640 --> 1dp = 1 * (640 / 375) = 1.7dp
dpi = 240 --> 1dp = 1 * (240 / 375) = 0.64dp
dpi = 160 --> 1dp = 1 * (160 / 375) = 0.426dp
//根据屏幕最小宽度的dp值创建文件夹
swdp 倍数关系
values-sw240dp 1dp = 0.64dp
values-sw320dp 1dp = 0.85dp
values-sw360dp 1dp = 0.96dp
values-sw375dp 1dp = 1dp
values-sw400dp 1dp = 1.06dp
values-sw480dp 1dp = 1.28dp
values-sw600dp 1dp = 1.6dp
values-sw720dp 1dp = 1.92dp
values-sw800dp 1dp = 2.13dp
values-sw820dp 1dp = 2.18dp
该倍数关系是以 750 x 1334 , dpi = 320 , sw-dp = 375作为基准的,如果以其他尺寸作为基准,则需要重新计算倍数关系