1 Android introduced a new set of unit DP and SP.
DP is the meaning of the density-independent pixels, also known as dip, and the ratio of its display in different density screens will be consistent compared to PX.
The SP is the meaning of the scalable pixel, it adopts the same design concept as DP, solves the problem of the adaptation of the text size.
2. What does density mean? The density in Android is the number of pixels per inch of the screen, usually in DPI. For example, a mobile phone screen width is 2 inches long is 3 inches, if its resolution is 320*480 pixels, then the density of this screen is 160dpi, if its resolution is 640*960, then this screen density is 320dpi, so the higher the density value of the screen display more fine effect.
According to Android rules, on the 160dpi screen, 1DP equals 1px, and on the 320dpi screen, 1DP equals 2px. Therefore, using DP to specify the width and height of the control ensures that the controls are displayed in a consistent scale across the screens of different densities.
3. When writing an Android program, try to specify the size of the control or layout as match_parent or wrap_content, if you have to specify a fixed value, use the DP as the unit, specify the text size using the SP as the unit.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Notes (ix) dimensions and units