Your approach is very complicated.
1. Don't use this scale,
scale = r.GetField("density"), it will give you
If you really want to use a scale you should use GetDeviceLayoutValues.Scale and this will give you a value of '3' for both devices!
2. Again, calculate in pixels and use dip values.
Or post a small project showing the problem.
Why not using:
mpos = 70%y 'scaling for various devices, button top will be at the 70% of screen height
For i = 1 To 26
lpos = 15dip + (colnum-1) * 35dip +(colnum-1) * xoffset '35 is swiftbutton width
tpos = mpos + (rownum -1) * 60dip
Addbutton(lpos, tpos, i, z)
z=z+1
colnum = colnum +1
If colnum > intendedcols Then rownum = rownum+1
If colnum > intendedcols Then colnum = 1
Next
the value xoffset must be in pixels.
Not tested.
Your routines could be simplified.