-
-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to get the correct DPI value on Android #369
Comments
How maximum different percent can be from DisplayMetrics.densityDPI and right DisplayMetrics.xdpi ? |
@FreakMurderer in theory - half of the bucket. Not sure what's the biggest one in practice. PS: There are very few valid reasons to use |
Even with newer SDL release versions, I believe this is still unimplemented. I think we'll have to use JNI and get this value ourselves http://stackoverflow.com/questions/3166501/getting-the-screen-density-programmatically-in-android |
I can confirm the (sdl) value is incorrect on android... |
Sorry for circling back on such an old issue. We started using JNI to calculate DPI on Android ourselves.
If you think we should modify our behavior for calculating Android DPI, open a pull request with a proposal 😄 Thanks everyone |
Hey guys,
Looks like there is a number of different ways to measure DPI on Android
Lime uses
DisplayMetrics.xdpi
, but a number of devices have this value completely wrongFor example Lint marks usage of "mm", "in" and other android metrics that rely on
xdpi
andydpi
with warnings - http://stackoverflow.com/questions/20631221/why-lint-shows-warning-when-using-in-inch-or-mm-millimeter-units-as-dimensio/22707894#22707894For example my Nexus 4 gives
xdpi
of 160 instead of expected 320, butdensityDPI
gives correct value of 320. It looks like it's a Cyanogen mod bug, since the latest stock Lolipop Nexus 4 gives correct 320 inxdpi
andydpi
. But what's important is that I have never noticed wrong sizing of UI on my nexus 4 in years, all because of the fact that all android UI sizing logic always relies onDisplayMetrics.densityDPI
instead ofxdpi
/ydpi
and only when I used DPI in Lime I've noticed that the value is wrong.Here Google http://developer.android.com/guide/practices/screens_support.html recommends using "dp" units which are based on
.densityDPI
and.density
and also shows code examples using.density
.To clarify why there are 2 different ways to access dpi -
xdpi
/ydpi
gives exact DPI value of a device.density
anddensityDPI
give a value of a nearest dpi bucket android os assigns a device to (120, 160, 240, 320, 480 or 640).So if a device has DPI of 330,
densityDPI
would return 320. I haven't done much Android development, but I think that is intended behaviour, though I'm not fully sure why.I propose to change a way Lime calculates DPI to a most commonly and widely used approach -
DisplayMetrics.densityDPI
.Of course it's wrong to change usage of API just because some phones/roms give a bugged value, but it's also important to use API in the most common way.
What do you guys think?
The text was updated successfully, but these errors were encountered: