Sub ExactSize As Double
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
r.Target = r.RunMethod("getDisplayMetrics")
Dim xdpi As Double = r.GetField("xdpi")
Dim ydpi As Double = r.GetField("ydpi")
Return Sqrt(Power(100%x / xdpi, 2) + Power(100%y / ydpi, 2))
End Sub
This will definitely come in handy one day.Note that this method returns the approximate size which is based on the approximate scale.
If you want to find the exact activity size then you can use:
This is only useful if the exact size is really important. For example if you create a ruler app.B4X:Sub ExactSize As Double Dim r As Reflector r.Target = r.GetContext r.Target = r.RunMethod("getResources") r.Target = r.RunMethod("getDisplayMetrics") Dim xdpi As Double = r.GetField("xdpi") Dim ydpi As Double = r.GetField("ydpi") Return Sqrt(Power(100%x / xdpi, 2) + Power(100%y / ydpi, 2)) End Sub
Tested on Nexus 7, it returns 7.668"Note that this method returns the approximate size which is based on the approximate scale.
If you want to find the exact activity size then you can use:
This is only useful if the exact size is really important. For example if you create a ruler app.B4X:Sub ExactSize As Double Dim r As Reflector r.Target = r.GetContext r.Target = r.RunMethod("getResources") r.Target = r.RunMethod("getDisplayMetrics") Dim xdpi As Double = r.GetField("xdpi") Dim ydpi As Double = r.GetField("ydpi") Return Sqrt(Power(100%x / xdpi, 2) + Power(100%y / ydpi, 2)) End Sub