A dip is a
density
independent
pixel.
When you set in the code positions and sizes of view it is bette to declare them with dips.
Example:
The above code means that the physical width of the butoon is:
60 pixels on a device with the standard density of 160, scale 1.
90 pixels on a device with a density of 240, scale 1.5.
45 pixels on a device with a density of 120, scale 0.75.
That means that the OS mutiplies the dimension by the scale factor.
Klaus -- I'm trying to make sure that I have all this straight for the Wiki.
If we say
Button1.Width = 60, then the button would take up 15% of the screen on a 400x240 screen width and 7.5% of the screen width on an 800x480 screen of the same physical size (say 4"). So by using
Button1.Width = 60dip, Android will scale the width up from 60 to 90, as you said above; however while 60/400=15%, 90/800 is only 11%, so the scaling will be off some.
So does Android base its scaling strictly on the 1 vs 1.5 density, or does it adjust for each device's actual dpi?
For example, the Galaxy SGS 4" device has a physical screen width of 3.5" and a resolution of 800x480. Dividing 800 by 3.5 = 228 dpi. The Motorola Defy is a 3.6" device with a screen width of about 3.25" and a resolution of 854x480 where 854/3.25 = 263 dpi. So while both devices are considered to have a density of 1.5, it would seem that Android would still need to adjust the sizes and positions of views to get the same layout to fit the same on both devices, or does it not try to get them precisely the same in such a case and that's when we have to use activity.height/width to fine-tune the adjustments as shown in
this post?
Also, the Galaxy SGS's height is about 1.875" which divided into 480 gives a vertical dpi of 256, but as calculated above, its horizontonal dpi is 228. So how does Android adjust for this difference so that a 100x100 (dip or not) square still shows up as square?
Also, a layout done on a 4" device with 240 dpi (scale=1.5) and a
Button1.Width = 60, will still have a button width of 60 on a 10" device with a resolution of 2100x1200 because such a device still has a dpi of 240 (scale=1.5), but it will appear to be much smaller on the higher resolution screen.
In fact, the entire layout done on a 800x480 Galaxy SGS would fit in the upper left quadrant of a 10" screen with 2100x1200 resolution, and that's the reason we normally have to create different layouts for different size devices, right? Or am I missing something about how this all works?