If, in a layout xml file, I set the size to be, for example 12dip. Will that always be 12px in mdpi and so 18px in hdpi?
So is dip always true for mdpi and will scale accordingly for other densities?
If, in a layout xml file, I set the size to be, for example 12dip. Will that always be 12px in mdpi and so 18px in hdpi?
So is dip always true for mdpi and will scale accordingly for other densities?
That question is fully covered by official documentation. Relations between dip, px and dpi are covered by this section.
Quote:
So the statement:
seems to be correct, according to the docs.
12dp will be 12px on a device with density 160 dpi. The docs don't say that all
mdpi
devices have exactly 160 dpi so it seems you might findmdpi
devices with other densities (e.g. 150 or 180 dpi). In those cases, the relation1dp = 1px
would not be true.You can only be sure of this relation:
If a device has a density of 320 dpi then each dp corresponds to 2 px, because 320/160 is 2. I would say that 2 is the "density factor", but it is also what you get with
getResources().getDisplayMetrics().density
, so it is also called "density".