Android commonly used units of measurement (px, dp, sp, pt, in)



1. px: point on the screen

pixel, which means pixel or resolution. Different devices have the same display effect. Generally, our HVGA represents 320x480 pixels, which is used more often.

2. dp: device independent pixels

device independent pixels, which means device-independent pixel dip. An abstract unit based on screen density. On a 160 dots per inch display, 1dip = 1px. May increase on displays larger than 160 dots.

3. sp: font unit

scaled pixels, which represent proportionally scaled pixels. This is a bit like the dp unit, but it also scales the size according to the user's font preference.

4. pt: 1/72 inch

point, represents a point. It is a standard unit of length, 1pt=1/72 inch, used in printing industry, very simple and easy to use.

5. in: unit of length

inch, means inches. is the physical size of the screen. Each inch equals 2.54 centimeters.

6. mm (mm): standard unit of length

millimeter, means millimeter.




Summarize:

  • 1. For the pixel setting of the layout, dip (dp) is generally used, so that it can be automatically adapted when displayed on a larger or smaller screen. If it is px, it is a physical pixel, so it may appear larger on a small screen , appear smaller on a larger screen.
  • 2. For font size settings, it is recommended to always use sp as the unit of text size, so that the user interface can be displayed normally on current and future display types.
  • 3. The size of text is always in sp unit, and the size of non-text is in dp unit.











Note:
Likes, comments, and reprints are welcome. Please give the link to the original text in an obvious place on the article page
. Those who know, thank you for reading my article in the vast crowd.
Where is the signature without personality!
For details, please follow me
and continue to update

Scan to have a surprise!
© 2021 05 - Guyu.com | 【Copyright All Rights Reserved】

Guess you like

Origin blog.csdn.net/weixin_49770443/article/details/117252380