Android-screen adaptation (1), android-Screen Adaptation
This article is based on the android video of MOOC.
1. Important Concepts about screens 1. What are screen sizes, screen density, and screen pixel density? A.
The screen size is the diagonal length of the mobile phone screen.
Unit: inch, 1 inch = 2.54 cm
B.
The screen resolution is the number of pixel points on the phone screen in the vertical direction.
Unit: px, 1px = 1 pixel
Generally, it is a vertical pixel.Horizontal pixels, such as 1080720
C.
The pixel density of the screen refers to the number of pixel points per inch.
Unit: dpi, short for "dot per inch"
The pixel density of the screen is determined by the screen size and resolution.
Calculation method: Take Huawei honor 3c for calculation. The screen size is 5 inch, and the resolution is 1280*720.
Its pixel density = (1280 ^ 2 + 720 ^ 2) ^ (1/2)/5 = 293.7
2. What are dp, dip, sp, and px? What is the relationship between them?
A. dp and dpi are the same thing. They have different names. To be consistent with sp, sp is now used. Dpi has been explained above, so there is no need to explain it more.
B. px is the smallest unit of the image.
C. sp is the unit of font size, which is an abstract pixel unrelated to scaling. The difference between sp and dp is that the android system allows users to customize the size of text (small, normal, hitting, super large, etc.). When the text size is normal, 1sp = 1dp = 0.00626 inch. When the text size is large or oversized, 1sp> 1dp = 0.00625 inch.
3. What are mdpi, hdpi, xdpi, and xxdpi? How to calculate and differentiate?
Both indicate pixel density.
| Name |
Pixel density range |
| Mdpi |
120-160 dpi |
| Hdpi |
160-240 dpi |
| Xhdpi |
240-320 dpi |
| Xxdpi |
320-480 dpi |
| Xxxdpi |
480-640 dpi |
2. How to Adapt to the screen 1. support various screen sizes
A. Use wrap_content, match_parent, and weight.
Warp_content: the size of the adapted content.
Match_parent: Is full of parent controls
Weight: This attribute is difficult to understand. Let's take a look at it for an example.
<! -- I simply won't write it all --> <Linearlayout> <Button android: id = "@ + id/button1" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_weight = "1"/> <Button android: id = "@ + id/button2" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_weight = "2"/> </Linearlayout>
For the above layout, the actual length = the length set by layout + the remaining length * weight
If the screen length is L, the layout setting values of button1 and button2 are both L, and the remaining length of button1 is the length of the total length L-button1-the length of button2, that is, the L-2L
L1 = L + (L-2L) * 1/3 = 2/3L
L2 = L + (L-2L) * 2/3 = 1/3L
In this way, we find that the weight value is the opposite, so we usually set it to 0dp.
This is the case.
L1 = L * 1/3 = 1/3L
L2 = L * 2/3 = 2/3L
B. Use consistent layout to disable absolute layout.
C. Use the qualifier-large
That is, the same layout file is simultaneously adapted to screen sizes of different sizes.
It is mainly used to adapt to the tablet.
D. Use auto-stretch bitmap
2. Support various screen density 3. implement adaptive user interface process
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.