Search code examples
androiddimensions

Why use unpredictable dips in Android instead of predictable pts?


72 pts is always equal to 1 inch, yet 160 dip is not always equal to 1 inch.

As such, why do people recommend us to use dips instead of pts?

Isn't it better to base our dimensions on pts which is predictable, instead of dips which is unpredictable?


Solution

  • The reason why you should use dip (Density Indepentdent Pixel) is that this way your application will support multiple screen sizes. This means that if you set a value to 100dip, it would be translated into 75px on a low density screen (ldpi), 100px on a medium density screen (mdpi), 150px on a high density screen (hdpi) and 200px on a extra high density screen (xhdpi) but the layout will look the same on each screen (but scaled to the screen density).

    The only reason to use pt is if you actually need the exact size and don't care about the screen density (I can't see when that would be the case).


    You should read through this article to better understand why dp/dip is the way to go:

    Supporting Multiple Screens

    Also this similar question has a good explenation of the difference between the different units:

    Difference of px, dp, dip and sp in android