Android Question Understanding dip values.

Nitin Joshi

Active Member
Licensed User
I am not much clear about dip values which we apply and trying to understand in detail. I have used 320 x 480, scale=1 (160dpi) variant in designer.

What will be the width value for 1, 2 & 3?

1) Button1.Width = 100dip
2) Button1.Width = 50dip
3) Button1.Width = 30dip

Thanks.
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
Sorry, i understood theory, now lets make me more clear with practical

Suppose, my device is 1080 x 1794, Scale=2.5 then what will be the Button1 width for 1, 2, and 3?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
1) Button1.Width = 100dip = 250 pixels
2) Button1.Width = 50dip = 125 pixels
3) Button1.Width = 30dip = 75 pixels
4) Button1.Width = 160dip = 400 pixels > ~ 1 inch = 25.4 mm
A size of 160 dip is about 1 inch. on all devices, density independent.
To get the pixel value you must multiply the dip value by the Scale.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
If you are worrying about button sizes in dip dimensions then you are probably not designing your layout in the best way. One might use dips to set the separation between views but the views themselves are best left to find their own best fit using the Designer and anchors, and maybe a Designer script. Here is a slightly complicated example, but there are several others with much simpler layouts that show the principle.

I am not saying that one should never use dip dimensions, but I am saying that when you design a screen layout properly you should not have to worry about the actual pixel dimension of the display, and certainly not about pixel scales and sizes. Usually I can use a single layout even for 'phones and tablets.
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
Dear Mr. Brian, thanks for your good guidance.

Do you mean to say anchors plus scripts (General or Variants) are enough to make design suitable for all types of screen sizes?
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Do you mean to say anchors plus scripts (General or Variants) are enough to make design suitable for all types of screen sizes?
Yes, I do. In fact even using variants is often a sign that you are on the wrong path.

When I started working with Android I did exactly what you are doing (worrying about screen dimensions) but it is not necessary; in fact it is the wrong way to go.

Another very useful tool is %x and %y. This works in the Designer too. A code example ...
B4X:
    Activity.AddView(panel1, 25%x, 25%y, 50%x, 50%y)
This will add a panel (or a label or an image) that will be in the exact centre of the screen of any device. The point that I am making is that it will work perfectly and we have not even thought about dips or pixel sizes!

Erel has produced some helpful videos using the Designer on You-Tube; make sure that you look them up. Good luck!
 
Upvote 0
Top