-
-
Notifications
You must be signed in to change notification settings - Fork 460
Please document the units for width/height etc. (in particular define what % is about but also cm, em, etc.) #218
Comments
Currently(version 1.5) width and height can be specified only in device Independent pixels(DIP). It is the default and not unit is required. "20%" is most likely parsed as 20 dips - the width you are getting. |
@vakrilov thanks for clarifying - and this issue https://github.com/NativeScript/docs/issues/210 asks for a clarification about what these DIP:s mean also. Does this mean that in {N}, forever, as long as no unit will be used, DIP will be what's meant? And all the hardcoded JS values like ".width", ".marginTop" etc. are counted in DIP:s? Please tell me the definition and how it plays out on Android, iOS and Windows Phone. https://en.wikipedia.org/wiki/Device_independent_pixel says the definition actually is 0.15875 mm at least on Android, i.e. not has anything to do with pixels. Please clarify? This is extremely important for making a layout consistent, so I really need to know, thanks :D |
Hi @mike-ense In short - all our layout properties (like width, height, margins, paddings, etc.) are in device independent pixels. Converting it to device pixels is done by multiplying device independent pixels and screen density. So it is not really fixed like 0.15875mm or something. |
@hshristov , aha. So on iOS, 1 DIP = 1 actual pixel on the display, and on Android, 1 DIP = 1 DIP, but there they indeed define it as 0.15875mm no? |
@mike-ense
|
@vakrilov , aha re iOS I understand. But on Android, should it be 0.15875mm? I think on my phone it looks like 2-2.5mm or so |
There is a pretty good explanation of density-independent pixels in the article that @hshristov posted: |
@vakrilov , so you mean on Android it's going to be somewhere approx in the 0.15-0.16mm range anyhow? Fair enough. :) |
Just as an update, there is an explanation of percentages now up at https://docs.nativescript.org/ui/layouts#percentage-support. For the DPI discussion I’m going to close this issue in favor of https://github.com/NativeScript/docs/issues/210. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Trying "width: 20%" on a button gives me a 0.4cm wide element. Looking in the documentation for what units exist e.g. px, cm, em, % and what that % relates to - like a box model or something - I don't find that.
Could you please document this?
Thanks!
The text was updated successfully, but these errors were encountered: