Why does Android have to be resolution and screen fit
The biggest reason is fragmentation, because Android's open source measures and the individual manufacturers ' own subtle changes, the result becomes this kind of
There are so many screen sizes that you need to fit:
How could that be t_t?
So we take care of most of the people, according to the league's statistics, as follows:
So you just need to fit:
Six resolutions of 800x480, 854x480, 960x540, 1184x720, 1280x720, 1920x1080 .
II. Basic Knowledge
Screen size
inches, 1 inches = 2.54 cm. For example, common screen sizes are 2.4, 2.8, 3.5, 3.7, 4.2, 5.0, 5.5, 6.0, etc.
Screen resolution (PX)
The screen resolution refers to the number of pixels in the horizontal portrait, which is the px,1px=1 pixel point. Generally in portrait pixel x transverse pixels, such as 1960x1080.
Screen pixel density (dpi)
Screen pixel density refers to the number of pixels per inch, which is the dpi, or "dot per inch" abbreviation. Screen pixel density is related to screen size and screen resolution, under a single change, the smaller the screen size, the higher the resolution, the larger the pixel density, the smaller the opposite. PPI =√ (length pixels ²+ width pixels ²)/Screen Diagonal inch number
Density-independent pixels (DIP/DP)
Density-independent pixels (density independent Pixels) are determined by screen pixel density and screen resolution, with 160DPI as the benchmark, 1DP (1DIP) =1px,320dpi when 1dp=2px.
Font size (SP)
An SP is a specially-prepared unit for fonts, and is solved in the same way as a density-independent pixel (DP).
MDPI, hdpi, xdpi, xxdpi, xxxdpi
According to Google's official rules, its representative pixel density is as follows:
General picture size requirements are as follows:
Third, the matching rules
3.1 Supports various screen sizes
Use wrap_content
andmatch_parent
Use as much as possible, android_width
android_height
wrap_content
match_parent
because these two properties are changed with the size of the container, so the adaptability is very strong.
Use relative layout to disable absolute layout
Use Relativelayout to maintain the relative position of the element and prohibit the use of absolute layout, because there are many problems with absolute layout.
Using qualifiers
Using Dimension Qualifiers
Res/layout/main.xml, single panel (default) layout.
Res/layout-large/main.xml, double panel layout.
Note the large qualifier in the second layout name directory. The system selects this layout on devices that are part of a larger screen, such as a 7-inch or larger tablet computer. The system will select a different layout (no qualifier) on the smaller screen.
Use minimum width qualifier
Res/layout/main.xml, single panel (default) layout.
Res/layout-sw600dp/main.xml, double panel layout.
In other words, for devices with a minimum width greater than or equal to DP, the system chooses the Layout-sw600dp/main.xml (double-sided Board) layout, or the system chooses the Layout/main.xml (single panel) layout.
Devices with an Android version below 3.2 Do not support this technology.
Using the screen orientation qualifier
Res/layout-land/main.xml Horizontal Screen
Res/layout-port/main.xml Vertical Screen
Layout Alias
The minimum width qualifier is available only for Android 3.2 and later. Therefore, if we still need to use a generalization size range (small, normal, large and extra) that is compatible with a lower version. For example, if you want to design the user interface to display a single panel on your phone, but display multiple panels on a 7-inch tablet, TV, and other larger devices, then we need to provide the following files:
Res/layout/main.xml: Single Panel layout
Res/layout-large: Multi-panel layout
RES/LAYOUT-SW600DP: Multi-panel layout
The latter two are duplicates, and only use values to set the same reference.
Res/layout/main.xml, single panel layout
Res/layout/main_twopanes.xml, double panel layout
Then add the two files:
Res/values-large/layout.xml:
<resources>
<item name= "main" type= "layout" > @layout/main_twopanes</item>
</ Resources>
Res/values-sw600dp/layout.xml:
<resources>
<item name= "main" type= "layout" > @layout/main_twopanes</item>
</ Resources>
The contents of the latter two files are the same, but they do not actually define the layout. They simply set main to the alias of Main_twopanes. Since these files contain large and SW600DP selectors, the system will apply these files to tablets and TVs regardless of the Android version (version less than 3.2 of tablets and TVs will match the large, and a version of a tablet and TV with a release above 3.2 will match sw600 DP).
3.2 Supports various screen densities
Use non-density to restrict pixels
For example, DP and SP, do not use PX.
Provide alternate bitmap
To generate these pictures, we should first extract the original resource in the vector format and then generate the corresponding picture for each density according to the following size range.
xhdpi:2.0
hdpi:1.5
mdpi:1.0 (Minimum requirements)
ldpi:0.75
That is, if we generate a 200x200 px size picture for the xhdpi device, we should use the same resource to generate the ldpi, 150x150, and 100x100 dimensions for the hdpi, MDPI, and 75x75 devices respectively.
The resulting picture file is then placed in the corresponding subdirectory under res/(MDPI, hdpi, xhdpi, xxhdpi), and the system automatically chooses the appropriate picture based on the screen density of the device running your application.
This way, as long as we reference @drawable/ID, the system can select the appropriate bitmap according to the DPI of the corresponding screen.
3.3 Practice
About HD Design diagram dimensions
Google officially gives the HD design of the size of the two options, one is designed to MDPI, and then to zoom to get a higher resolution of the picture, the other is a high resolution as the design size, and then according to the multiple corresponding to the small resolution of the picture.
Based on experience, I recommend the second method, because the small resolution will result in pixel loss when generating high-resolution pictures.
The resolution can be designed with 1280x720 or 1960x1080 as the primary resolution.
Using Point 9 Diagram, point 9 diagram is a special picture format in the application development of the Andriod platform, the file name extension is:. 9.png.
The black line on the left and the top indicates the stretch area,
The black line on the right and below indicates the foreground content display area.
Use a Third-party library for percent layout.
Iv. Summary
For the mobile side of the screen adaptation, recommend the Web side experience, use the percentage layout, which can save a lot of trouble. OK, about the Android resolution and screen adaptation we are introduced to this, if there are questions you can message exchange. I hope this article will be helpful to everyone.