1. Screen adaptation qualifier
When the Android system loads application resources, it will load resources under different screen adaptation qualifier directories according to the relevant attributes of the device currently running the application, such as: screen size/screen pixel density/aspect ratio/screen orientation and other attributes;
For example: when switching between horizontal and vertical screens, the res/layout-land directory stores the horizontal screen layout, and the res/layout-port directory stores the vertical screen layout;
Screen size qualifiers:
small : small screen;
normal : standard screen;
large : large screen ;
xlarge : extra large screen ;
Screen density qualifiers:
ldpi : low screen pixel density, 0 < dpi ≤ 120 ;
mdpi : medium screen pixel density, 120 < dpi ≤ 160 ;
hdpi : high screen pixel density, 160 < dpi ≤ 240 ;
xhdpi : super high screen pixel density, 240 < dpi ≤ 320;
xxhdpi : ultra-high screen pixel density, 320 < dpi ≤ 480 ;
xxxhdpi : ultra ultra ultra high screen pixel density, 480 < dpi ≤ 640 ;
Screen orientation qualifier: generally used for adaptation when switching between horizontal and vertical screens;
land : horizontal line screen;
port : portrait screen;
Screen aspect ratio qualifier: The standard screen aspect ratio is 16:9 16:916:9;
long : The screen that is longer than the standard screen, such as 20 : 9 20:920:9 , 21 : 9 21:921:9 ;
notlong : standard screen;
2. Mobile phone/tablet device screen adaptation
Tablet PC market share
The Android tablet market share is as follows, probably still accounted for about 40%, so tablet adaptation is still very important;
Density-Independent Pixel Computing
In general, the layout or image resources of the tablet are placed in the res/layout-swxxdp directory, where xx is the horizontal density-independent pixel (DIP, Desity Independent Pixels) value, and the unit is dp / dip;
In [Android Screen Adaptation] the basic concept of screen adaptation, the screen pixel density (Dots Per Inch, the number of pixels per inch) of a 6.5-inch screen, 1920 × 1080 pixel screen is calculated, and the value is 500, that is, each Inches have 500 pixels;
The device has a lateral density-independent pixel ( DIP , Desity Independent Pixels ) value of 345.6;
mobile device qualifier
Add the sw360dp qualifier to the layout or image directory name, which is compatible with almost all mobile devices; currently, the screen width of mobile phones on the market rarely exceeds 360;
As long as the horizontal density-independent pixels ≤ 360, you can use the resources under the sw360dp qualifier, such as the resources under the res/layout-sw360dp directory;
tablet qualifier
In layout or image directory names,
Add sw480dp qualifier, corresponding to 7-inch tablet computer;
Add sw560dp qualifier, corresponding to 8-inch tablet computer;
Add sw720dp qualifier, corresponding to 10-inch tablet computer;
Add sw800dp qualifier, corresponding to 11-inch tablet computer;
For example, the dpi of Mi 5 is 480, and the horizontal pixel is 1080px. According to px=dp(dpi/160), the horizontal dp value is 1080/(480/160), which is 360dp. The system will search for the existence of value-sw360dp folder and corresponding resource files. If it cannot be found, the system will search downwards, and the folder value-sw320dp will be found in the picture below.
Huawei matePad11 takes the display size standard as an example:
display size |
sw |
maximum |
420dp |
larger |
480 dp |
big |
533dp |
default |
640dp |
smaller |
720dp |
Lenovo Xiaoxin pad plus sw is 800dp
You can use the screenMatch officially recommended by Google for adaptation