Screen adaptation blog: https://www.jianshu.com/p/1302ad5a4b04 https://juejin.cn/post/6844903641610977288 px=density*dp density=dpi/160 Px =dp*(dPI /160) First of all, the screen adaptation solution is not to solve the normal display of different devices, want to achieve the goal of normal display can be achieved through adaptation skills, try to ask the early only DP adaptation, there is no other screen adaptation solution, UI on different devices can not be displayed properly? Screen adaptation solutions are designed to address UI consistency across devices. Adaptation scheme: 1. Dp adaptation: In the official adaptation scheme, DP will be converted into the corresponding PX according to the specific DPI (Density) of the device. In screens with different resolutions, the actual display sizes are generally the same, but there will be devices with the same density but different resolutions. Therefore, all adaptation problems cannot be solved, but it can be used in combination with adaptation techniques. 2. Resolution qualifier adaptation: blog:https://blog.csdn.net/lmj623565791/article/details/45460089 according to benchmark generate different resolution dimens files, geometric scaling of px values, nature is the percentage of adaptation, high defect is invasive, There are too many Dimens files, and the device resolution must match the values folder completely to achieve the adaptation, resulting in low fault tolerance. 3. Minimum width qualifier adaptation: blog: https://www.jianshu.com/p/1302ad5a4b04 https://juejin.cn/post/6844903681524006925 qualifier adaptation principle and resolution is consistent, the former is based on reference resolution, Minimum width qualifier adapter is generated according to the benchmark minimum width different minimum width limit dimens files, geometric scaling of dp value, nature is also compared percentage adaptation resolution qualifier adaptation, advantage is that the resolution of the equipment is too fragmented, and the minimum width of mainstream (dp) is a relatively limited, so the dimens file is less, And in the case of no perfect match, it will also look down to the nearest minimum width, which has a certain fault tolerance. The disadvantage is also high invasiveness. 4. Density adaptation blog:https://mp.weixin.qq.com/s/d9QCoBP6kV9VSWvVldVVwA (the original) according to the px = density * dp, both 1 dp = density px, the core of this solution is that change the definition of dp adaptation, The original density= Dpi /160, since the relationship between DP and PX is based on the DPI value of the device, the problem is that the device with the same DPI, the same DP value corresponds to the same PX value, but the resolution of the device may be different, although the real size is roughly the same, but the proportion is different, resulting in different UI display effects. Density adaptation scheme is based on the width of a certain direction of the device instead of dPI. On any device, the width is this dp value, so on different devices, the px value corresponding to 1DP is the width/base width (DP) of the target device in one direction. Both set density = devicePxWidth/standardDpWidth here, why use dp base width, no px, because px is a fixed value, write how much is how much, no conversion, of course one can define your own units such as call PXX, this unit as a fixed value, Each device corresponds to a different specific PX value, this is not dp, and also have to implement their own conversion process. The advantage is that it is less intrusive, but the disadvantage is that the density is changed globally, so the display effect of some system native UI and third-party library UI will be inconsistent with the original because the DP value is not written based on the base width (DP) specified by us. 5. Pt adaptation (Kirgiku) : Px =dpi*inch px=dpi*inch px=dpi*inch px=dpi*inch px=dpi*inch px=dpi*inch px=(dpi/72)*pt Change the density so that the DP value of the design is always equal to the screen width on different devices. Again, px=(dpi/72)*pt, change the DPI so that the pt value of the design is always equal to the screen width on different devices. So just need to dpi = 72 * (devicePxWidth/standardPTWidth) since why are all the same in pt, because of shortcomings in the density adaptation scheme is density change, cause the system UI, third party UI and the effect is not consistent, so that it does not change the density, You can avoid this problem. In fact, it doesn't matter which unit is used for the design. Dp, PT and PX are determined by ourselves, so whether the design is 1080x1920px or 1080x1920DP, So whatever we do, let's just think of it as the base dp and pt, the base width is 1080dp/pt, and when we calculate the relationship between px and dp and pt on different devices, then all the ratios of the widths of the UI and the device are the same, and we're done with the adaptation. The only problem is how to preview, because the consistency effect has to be up and running for the dynamic calculation to appear. The answer is to create a virtual device with a ratio of 1:1px=1dp, 1px=1pt. This way the preview will look exactly like the design. The next problem is how to create pT-adapted virtual devices, given the length and width, and screen size parameters. Because our goal is to create a 1px=1pt device. Therefore, px=(dpi/72)*pt indicates that the dPI of the virtual device is 72. Because DPI =(√ W ^2+h^2)/inch, inch=(√w^2+h^2)/72Copy the code