Greetings, all.
Thank you for your replies.
In the code below:
The result is in dpi and not in dip.
The question is, what factor is used for the computation of width in dpi?
Is it from xdpi (see ExactSize - code from Erel):
or is it from:
In some cases, the factor is the same, but in the majority of cases (at least, in what I have seen), the xdpi is different than the scale (most of the time smaller).
Best regards.
Sandy
Thank you for your replies.
In the code below:
B4X:
MenuTextSize=CanvasMenu.MeasureStringWidth(MList.Get(i),Typeface.DEFAULT,20) 'in dpi not dip
The result is in dpi and not in dip.
The question is, what factor is used for the computation of width in dpi?
Is it from xdpi (see ExactSize - code from Erel):
B4X:
Sub ExactSize As Double
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
r.Target = r.RunMethod("getDisplayMetrics")
xdpi = r.GetField("xdpi")
ydpi = r.GetField("ydpi")
'Return Sqrt(Power(100%x / xdpi, 2) + Power(100%y / ydpi, 2))
Return Sqrt((100%x / xdpi)*(100%x / xdpi) + (100%y / ydpi)*(100%y / ydpi))
End Sub
or is it from:
B4X:
Sub GetDevicePhysicalSize As Float
lv = GetDeviceLayoutValues
Log(GetDeviceLayoutValues)
Return Sqrt(Power(lv.Height, 2) + Power(lv.Width, 2)) / lv.Scale / 160
End Sub
In some cases, the factor is the same, but in the majority of cases (at least, in what I have seen), the xdpi is different than the scale (most of the time smaller).
Best regards.
Sandy