To use "dp" (Device Pixels), or not to use "dp"; That, is the question.

You must Login before you can answer or comment on any questions.

So I keep reading around (and I believe I saw in the documentation) that using "dp" (device pixels) is the best way to setup your UI. From experience with 6 different Android phones now, this has got to be impossible. If it were that case, I'd have to create multiple different layouts for difference size devices. Using just the integer (20 instead of 20dp) gives me pretty much the same result across all 6 devices. Why does everyone keep saying use "dp" instead of without it? Are you not running into the same issue I am? Using "20dp" on a EVO 4G looks way off compared to a Samsung Galaxy S III and then other tablets. Now, I'm wondering if this will happen on iPhone's now with the retina vs non-retina phones vs iPhone 5 screen-size increase.

1 Answer

dp is the way to go when you need to support multiple screens. Don't take your initial tests for granted. There will be instances where things just won't scale on Android (especialy on small displays). So Density Pixels (not Device Pixels) is the only way to ensure that an object will have the same proportion regardless of the screen.

— answered 7 months ago by Christian Brousseau
answer permalink
2 Comments
  • Thanks for the quick reply but I don't get why there's such a huge difference when adding dp. The display gets way off. I'm not sure how to even go about styling views when there is such inconsistency between each device.

    — commented 7 months ago by Troy Steuwer

  • What I used to do was to develop it once in pixels. (for iPhone for example) Once that was done, I went through the code and *converted *all values to dp. If your application loos the same after that, it means you succeeded.

    From there, you will be sure that everything will scale on different devices.

    Quick tip: You can change the default unit of an app in a single place. This will prevent you from having to add dp everywhere in your code.

    — commented 7 months ago by Christian Brousseau

Your Answer

Think you can help? Login to answer this question!