0

I have an Android application that needs to run on one specific device. Its display:
- is considered as ldpi (according to my calculations and getResources().getDisplayMetrics().densityDpi)
- has width of 1440px, from which Android should see only 940px.
When I call getResources().getDisplayMetrics().widthPixels it is really 940, but actually layout-w1140dp gets loaded, and not layout-w940dp (I have created several layout folders just to see what will be loaded).

The main issue I have is that even though I have set the width of my activity's main layout to be 940dp, what I observe is that it is actually filling like 3/4 of the screen width. It seems like Android resizes the drawables from the drawable-ldpi folder when displaying on a display with 940px width.
Am I getting it wrong to think that if you have the drawables and layout files for the specific display in the correct folders and in a layout you set 940dp, it should really be 940px on that display?


So I replaced every dp with px in my layout file and now it seems fine. Obviously I need to re-read more carefully Android's documentation, because I had wrong understanding of dp. I have some new questions, but I guess it will be better to ask in a separate questions.

ligi
  • 39,001
  • 44
  • 144
  • 244
dragi
  • 3,385
  • 5
  • 22
  • 40
  • `is considered as ldpi` ... **really**? how many dpi does it report? `So I replaced every dp with px` this is only valid for **mdpi**, not ldpi. You should **always** use `dp` for views and `sp` for text sizes. – Phantômaxx Oct 07 '14 at 15:53
  • @FrankN.Stein It reports 125dpi. And why I should **always** use dp for views? – dragi Oct 07 '14 at 16:55
  • 125 dpi is **ldpi**, without any doubt. Because dp are **scalable**. px aren't. If you are to support **one device only**, then just don't care. But this shouldn't be your aim. – Phantômaxx Oct 07 '14 at 16:59
  • Actually it is exactly what I aim for (I have written in the first sentence of the question, maybe it was not that clear). This application needs to run on only one specific device. And using **dp** didn't work for me, but **px** seemed to work (at least on emulator, I will try tomorrow on the real device). – dragi Oct 07 '14 at 17:07

1 Answers1

0

DP and px are very different things. DP are density independent pixels, see this question here for some more information on the difference.

Community
  • 1
  • 1
AndroidNoob
  • 2,771
  • 2
  • 40
  • 53