Common length units include PX, dip, and sp.
1. PX (pixels) pixels: a large number of pixels are used. Generally, hvga represents 320x480 pixels.
2. Dip or DP (device independent pixels) Independent pixels: This is related to the hardware of the device. We recommend this option to support WVGA, hvga, and qvga cwj, instead of pixels.
3. Sp (scaled pixels-best for text size) pixel amplification: mainly deal with the font size.
The following is not frequently used:
4. In (INCHES) inches + V % R9 K,
[7 d * T3 H: V! W
5.mm (millimeters) mm )~ '
D & V "E3 @
6. Pt (points) Point
The following is a back-to-back example of how to calculate the statusbar height on the Android platform .;
E) D3 ~ # @ 5 Q6 x9 O & o8 L
By default, the statusbar height is 25 dip, and this value will not change, whether your screen is 240*320, 600*800 or other resolutions, the statusbar height is 25dip. +
S8 D2 A1 H/z "B3 ~ $ G;] * l
Maybe some people may say, how is it possible? The height of the statusbar on a device with a value of 600*800 is much higher! T7
I * F7 d $[8 Q $ C9 \
Yes. On a device like 600*800, the height of the statusbar looks indeed much higher than that of the 240*320 screen, but it is indeed 25 dip, but it is not 25px at this time.
On a device with a resolution of 240*320, 25dip is 25 pixels (25px) in length or height when displayed on the device; but on 600*800 devices, the 25dip is no longer 25px. 4
L2? -} "X! I3 I! ?
& H-V I4 K9 Z, h
Next we will teach you how to achieve this height on different devices. In fact, it is very simple:
Displaymetrics metrics = getresources (). getdisplaymetrics ();
Int status_bar_height = (INT) math. Ceil (25 * metrics. Density );
In fact, what we need to do is to convert the height of the 25dip to PX, because the height we need in the code is in PX. 9
Z9} 9 U! B &} (N % u #
9], M + [3 _ * r! 'V' W
Take the screen with a resolution of 480*800 as an example: metrics obtained in the preceding statement. the density value is 1.5. Multiply the value 1.5 by the height 25 of the statusbar, and then perform an integer to get the height 38, which is at the resolution of 480*800, the height of the statusbar.
3 H9 I. J6 I9 I4 W3 Y & E
Here, we need to note that math is used in the Integer Operation. ceil.
Common length units include PX, dip, and sp.
1. PX (pixels) pixels: a large number of pixels are used. Generally, hvga represents 320x480 pixels.
2. Dip or DP (device independent pixels) Independent pixels: This is related to the hardware of the device. We recommend this option to support WVGA, hvga, and qvga cwj, instead of pixels.
3. Sp (scaled pixels-best for text size) pixel amplification: mainly deal with the font size.
The following is not frequently used:
4. In (INCHES) inches + V % R9 K,
[7 d * T3 H: V! W
5.mm (millimeters) mm )~ '
D & V "E3 @
6. Pt (points) Point
The following is a back-to-back example of how to calculate the statusbar height on the Android platform .;
E) D3 ~ # @ 5 Q6 x9 O & o8 L
By default, the statusbar height is 25 dip, and this value will not change, whether your screen is 240*320, 600*800 or other resolutions, the statusbar height is 25dip. +
S8 D2 A1 H/z "B3 ~ $ G;] * l
Maybe some people may say, how is it possible? The height of the statusbar on a device with a value of 600*800 is much higher! T7
I * F7 d $[8 Q $ C9 \
Yes. On a device like 600*800, the height of the statusbar looks indeed much higher than that of the 240*320 screen, but it is indeed 25 dip, but it is not 25px at this time.
On a device with a resolution of 240*320, 25dip is 25 pixels (25px) in length or height when displayed on the device; but on 600*800 devices, the 25dip is no longer 25px. 4
L2? -} "X! I3 I! ?
& H-V I4 K9 Z, h
Next we will teach you how to achieve this height on different devices. In fact, it is very simple:
Displaymetrics metrics = getresources (). getdisplaymetrics ();
Int status_bar_height = (INT) math. Ceil (25 * metrics. Density );
In fact, what we need to do is to convert the height of the 25dip to PX, because the height we need in the code is in PX. 9
Z9} 9 U! B &} (N % u #
9], M + [3 _ * r! 'V' W
Take the screen with a resolution of 480*800 as an example: metrics obtained in the preceding statement. the density value is 1.5. Multiply the value 1.5 by the height 25 of the statusbar, and then perform an integer to get the height 38, which is at the resolution of 480*800, the height of the statusbar.
3 H9 I. J6 I9 I4 W3 Y & E
Here, we need to note that math is used in the Integer Operation. ceil.