I have been reading about dp, px, ppi
and dpi
for awhile now, and I am lost.
Why is it that a large phone like the Galaxy Note 3
(with a 5.7 inch
display) can have the same dp
as a Moto X
(with only 4.7 inches
)?
My calculation for each returns a width=360dp
and height=640dp
. It seems like many higher density phones fall in this range. Is this true or am I misunderstanding dp
?
I am using the following to calculate my values: How to determine the screen width in terms of dp or dip at runtime in Android?
Because it's not just a matter of screen size, it is also a matter of screen density. I'll explain. The convertation formula from px to dp units is as follows:
dp = px * 160 / dpi, where dpi is your screen density.
Consequently, from the values you calculated (let's take the width) we have the following values for the screen density:
Galaxy Note 3 (width = 1080 px): dpi = 1080 * 160 / 360 = 480
Moto X (width = 720 px): dpi = 720 * 160 / 360 = 320.
Galaxy Note 3 and Moto X have the same width = 360 dp because of equal width/dpi ratio = 2.25 (same for the height/dpi ratio = 4). Now imagine Moto X has the same density as Galaxy Note 3. In that case you'd get a smaller width = 240 dp for Moto X.
来源:https://stackoverflow.com/questions/22799390/why-does-my-galaxy-note-3-have-the-same-dp-dimensions-as-a-much-smaller-phone