3

I am designing a layout as per a set of specification. I basically need to give some space between the layout and the android device. Below image is for reference

enter image description here

I am using following site to convert given pixel into dp values AndroidPixelConverter

I am giving px value in xxxhdpi column and getting its respective dp value, which I am placing it in my xml layout.

The primary phones that I am testing on is Samsung S4 and Nexus5

Following are my questions:

  1. According to this site Nexus5 and Samsung S4 belongs to xxhdpi resolution but still I am getting the correct pixel value if I use the xxxhdpi column in the above mentioned AndroidPixel Converter site. Why is this ?
  2. Nexus5 has soft navigation bar where as Samsung S4 has hard button as navigation. How can I detect it and accordingly give values to my layout. The navigation bar, if I am not wrong is of 144px in height, if not present will change the layouts dimension. How can I handle this ?

Lastly, is the method which I am following the correct one? If no, please guide in the correct way.

P.S: I am looking for pixel perfect layouts across all devices. Is it possible ?

ik024
  • 3,566
  • 7
  • 38
  • 61
  • Are you sure you need to leave space measured in pixels? That's actually a bizarre requirement. On different device densities, 115 pixels at the top can range from almost an inch (on ldpi devices) to about 1/6 of an inch (on xxxhdpi devices). – Ted Hopp Apr 28 '15 at 06:22
  • Hi did u check http://developer.android.com/guide/practices/screens_support.html – Dilip Apr 28 '15 at 06:22
  • **"I am looking for pixel perfect layouts"** : There is no such thing with Android devices due to the fact there are hundreds of different manufacturers and thousands of different devices. Android isn't a physical device specification - it's an operating system which is open source and can be used be anyone privately or commercially - screen sizes *WILL* vary, screen aspect ratios *WILL* vary. Attempting to work with absolute pixels will fail - use percentage dimensions and Android will adjust accordingly. The average user won't notice slight variations across different devices. – Squonk Apr 28 '15 at 06:32
  • @TedHopp I am converting it into dp values that shud be fine right ? – ik024 Apr 28 '15 at 06:32

1 Answers1

3

You need to talk to your designer and go about things in a different way. You NEVER want to specify a layout in px like that. It won't scale- a px can be any size. Go back to him and get a dp number instead (a dp is basically 1/160th of an inch). Design the whole thing in dp. Then let the phone itself translate it to px.

If you design in pixels, it will not work. Design in physical dimensions (dp), and let the device translate.

Also, you can't assume the height of the nav bar. It can, and does differ between devices both in terms of dp and px.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • I am not designing as per px values. I am converting it into dp values from AndroidPixelConverter site mentioned above. It should work right? – ik024 Apr 28 '15 at 06:28
  • No. You're doing it backwards. Specify everything in your design in dp, not px. Why would you convert, then have it convert back on the phone? The phone itself at the lowest level works at px and not dp, it will have to translate. Decide how big you want everything in dp, and specify a single layout that way. – Gabe Sechan Apr 28 '15 at 06:35