dip sp px dpi resolution and other size differences

ldpi QVGA (240×320)

mdpi HVGA (320×480)

hdpi WVGA (480×800),FWVGA (480×854)

xhdpi 720P (1280*720)

xxhdpi 1080p 320 (Half-size VGA)

SVGA 800*600 (Super VGA)

5:3

WVGA 800*480 (Wide VGA)

16:9

FWVGA 854*480 (Full Wide VGA)

FWVGA 854*480 (Full Wide VGA)

< p> HD 1920*1080 High Definition

QHD 960*540

720p 1280*720 SD

1080p 1920*1080 High Definition

Pixel Density

HVGA mdpi

WVGA hdpi<

FWVGA hdpi

720P(1280*720) xhdpi

1080P(1920*1080) xxhdpi

Density Suggested Size

mipmap-mdpi 48 * 48 1

mipmap-hdpi 72 * 72 1.5

mipmap-xhdpi 96 * 96 2

mipmap-xxhdpi 144 * 144 3

mipmap-xxxhdpi 192 * 192 4

1. Calculate dpi ----> pixels per unit inch

For example, if there's a cell phone with a 4-inch screen and a resolution of 480X800, how do you calculate its dpi?

Because we don't know the length of the sides, surely we can't count them separately, and 4 is the diagonal length, so we can directly use the collinear theorem to count the diagonal pixels, divide by 4, and figure out that it's probably dpi = 233 pixels per inch.

Then the density is (233 px/inch)/(160 px/inch)=1.46 or so

By the way, android has only 3 dpi by default, low, medium and high, corresponding to 120, 160, 240, if there is no special setting, all the dpi will be counted into these 3, of which default is 120, 160, 240.

2. Calculate dp and px

When we write layouts, we definitely still need to know how many px there are in 1 dp.

The conversion formula is as follows: dp = (DPI/(160 pixels/inch)) px = density px

Note that there are units here. px is a unit, dp is a unit, and density has no unit.

For convenience, let's say the dpi is 240 pixels per inch, then the density is 1.5

Then dp=1.5px, note that this is in units, i.e., device-independent pixels = density pixels, then converted to numerical values, it should be the following equation

PX = density * DP

Density = density * DP

PX = density = density px. density * DP