Android Question I'm totally confused with dip concept

Himred

Member
Licensed User
Longtime User
Hello,

I'm new to B4A and I'm trying to code a simple app.
I do not use the designer as I build a dynamic interface, thus I use AddView to create and attach views (buttons/lists,...)
I specified all coordinates as dip, ie : TopX=230dip, I tested on a galaxy tab and the layout was fine.
When I tryed it on my Xperia Z1 phone, it did not scale and some buttons where out of the screen.
After reading docs, I thought (But I'm clearly wrong) that using dip was the right way to make sure interfaces scales "magically"'.

Another related question, how can I retrieve the screen resolution in my code ?

Someone could point me on a link where this stuff is explained because right now I'm confused.

Thanks a lot for your help !
 

klaus

Expert
Licensed User
Longtime User
When using dip values you get almost the same physical dimensions independant of the screen density.
If you use Button.Width = 160dip the button width will be almost 1inch = 24.4 mm
It does not scale for different screen sizes.
It will be 1 inch on all screens small and big ones.
If you want to adapt the dimensions for different screen sizes you can use %x and %y values or use the AutoScale Module as already suggested by LucaMs.
 
Upvote 0
Top