DIP – Density Independent Pixel, is a measurement unit, mainly used in Android, that hides the real screen scale. 160 dips is roughly 1 inch on all devices.
Different devices have screens with different scales.
The definition of scale in B4A is <number of pixels per inch> / 160.
It is a common mistake to compare resolutions without the scale value. The width and height are meaningless without it.
For example, a device with resolution of 1200 x 800, scale = 1.0 is a 9” tablet and a device with 1080 x 1794, scale = 2.6 is a 5” phone.
In order to make things simpler, B4X has built-in support for ‘dip’ units. Instead of writing:
Button1.Width = 100 * DeviceScale
We can write:
Button1.Width = 100dip
Note that there is some approximation here. The more accurate screen scale is actually made of two values, one for the horizontal scale and one for the vertical scale. This only matters if you want to build a “ruler app”, and even in that case you will find that the reported accurate values are not always 100% accurate.
A properly built layout shouldn’t target any specific screen size. Use anchors and designer script to build a flexible layout.
Note that the ‘dip’ unit is also available in B4J and B4i, however the scale is always 1.0 as the underlying SDK takes care of handling different scales.
Video tutorial about this topic: