Inches to pixel on android studios

Started by
12 comments, last by LAURENT* 7 years, 1 month ago

It all depends on the precision you need and why you need it.

Is a reported 114 DPI close enough for a device that physically is 117?

Is a reported 180 DPI close enough for a device that physically is 188?

Is a reported 180 DPI close enough for a device that is 215? Or 240?

If your goal is to display a ruler image with centimeter accuracy, calibrate it. If you are looking for ballpark correct so you can scale the UI, use the number the system reports after doing a quick sanity check, and even better provide an option the user can adjust to set the scale rather than only doing it mathematically.

Advertisement

For UI scaling, it should definitely be enough to just rely on DisplayMetrics. Do you really need a "sanity check"? (and how would you do it? A big list of device IDs? All you have is the information you get from DisplayMetrics, afaik there is no other way to know the physical size of the device) I still doubt there are devices which report truly garbage values there. If they did, wouldn't all apps fail on that device, since the application framework relies on DisplayMetrics internally to select resources for and scale the android UI?

If a device manufacturer have chosen to report a very different DPI (like 180 instead of 240) it would mean all UI on that device looks smaller then on a "normal" android device, but in that case the user is likely to be accustomed to a smallish UI.

It's of course a nice service to your user to provide a UI scaling option, but I don't think it is something that need to be a priority.

I totally agree that it would be really nice if the device manufacturers got their shit together and just reported the actual DPI though... In our game we have a multitouch gesture engine with lots of complicated and quick gestures, and if we don't know the physical size of the device we can't give a consistent game play experience across devices. There are other issues that makes that practically impossible though, so we decided relying on DisplayMetrics is "good enough".

but most of games on google store seems to acutally get proper x,y coordinate where you touch it so there should be some way of getting that position (since he asked about ppi i am 100% sure he wants to get proper touch x,y coord)

but most of games on google store seems to acutally get proper x,y coordinate where you touch it so there should be some way of getting that position (since he asked about ppi i am 100% sure he wants to get proper touch x,y coord)

Nope, I don't want the touch coordinates. I could easily figure that out. I think I worded my question wrong but I did come up with a new solution. I was concerned about the user point of view and wanted to turn inches to pixels but first I needed to figure out how to get the pixel to inches. I was looking way too far ahead.

I decided to go on a new solutions of using screen percentage. By calculating the percentage I wanted objects to be scaled relative to the phone pixel dimensions I was able to get really accurate result in resizing them. With this technique in hand I was also able to get accurate positioning too using percentage calculations.

I'm expecting a small percentage error using this but I don't mind. My game only response to "onTouch".

This topic is closed to new replies.

Advertisement