How do dp, dip, dpi, ppi, pixels and inches relate?

前端 未结 5 1122
别那么骄傲
别那么骄傲 2020-12-24 02:33

I was reading dp, dip, px, sp measurements, but I still have some questions about dp/dpi vs ppi vs px vs inch. I am not able to compare them... is an inch the largest?

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 02:51

    How do dp, dip, dpi, ppi, pixels and inches relate?

    For the purpose of android development:

    dp = dip
    dpi = ppi
    inch x dpi = pixels
    dp = 160 x inch
    dp = 160*pixels/dpi
    

    So, on a 160dpi phone (mdpi):

    2 inches = 320 dp
    2 inches = 320 pixels
    

    On a 180 dpi phone:

    2 inches = 320 dp
    2 inches = 360 pixels
    

    Note that 2 inches is ALWAYS 320dp, independent of screen size. A dp is a physical distance of 1/160th of an inch.

    The dp to pixels formula is interesting:

    dp = 160*pixels/dpi
    

    Is equivalent to:

    dp = pixels/(dpi/160)
    

    dpi/160 is an interesting factor. Its the relative density compared to android's mdpi bin and the amount you must scale your graphics by for the various resource bins. You'll see that factor mentioned a few times on this page, 0.75 being the factor to ldpi.

提交回复
热议问题