Android screen adaptation solution
Screen Size:
The length of the diagonal line of the screen, in inches, 1 inch = 2.54 cm
Resolution
The unit of pixel points on the horizontal and vertical lines is px, and 1 px = 1 pixel is usually vertical * horizontal pixel, for example, 1920*1080.
Screen pixel density
The Unit dpi of the pixel points per inch (on the diagonal line of the screen). The calculation method is 1920*1080 dpi = 445 Based on the screen size and pixels: sqrt {1920 ^ 2 + 1080 ^ 2}/size (4.95 diagonal)
Px, dp, dip, sp
Dp dip is a density-independent pixel that uses 160dpi as the benchmark. 1dip = 1px is on the host of 320*480: 160 dpi 1dp = 1px on the host of 800*480: 240 dpi 1dp = 1.5 pxsp, do not set an odd number or decimal number when setting the font size, because it may cause loss of precision.
Mdpi, hdpi, xdpi, xxdpi
The system selects different pixels for the same image. Similarly, different values of dimen are defined in values in different pixels. M 120 ~ 160 (dpi) h 160 ~ 240 XH ~ 320xxh 320 ~ 480 xxxh 480 ~ 640
Solution supports various screen sizes (available in code)
### Use wrap_content match_parent weight (Weight). For example, if two buttons exist on the screen and their weights are respectively set to 1 or 2. When the width is set to match_parent, the 1-weight button actually accounts for 2/3 of the screen, what's going on? Originally, the width calculated on the screen = the original width + remaining space * Percentage of the control # use relative layout, no absolute layout # Use the qualifier res/layout-large/greater than 7 inch when using this layout min width res/layout-sw600dp direction qualifier values-sw600dp-land/layout horizontal direction values-sw600dp-port/layout vertical direction # Use automatically stretch the bitmap. 9. the top left of the image is the stretching height, and the bottom right is the spacing.
Supports various screen density (for images meeting various dpi requirements) to implement adaptive user interface processes (mainly for tablet adaptation)