# Android QuestionCalculate Physical Screen Size

#### wonder

##### Expert
Longtime User
Hi guys!!

Given the resolution and dpi, is it possible to calculate the screen physical size in centimeters?

I know this is simple math, but my brain refuses to work anymore today.

#### NJDude

##### Expert
Longtime User
With this code you get the size in inches:
B4X:
``GetDeviceLayoutValues.ApproximateScreenSize``
Just multiply the result by 2.54

#### wonder

##### Expert
Longtime User
Wow, it's even easier than I thought!! Thank you very much!!! #### Erel

##### B4X founder
Staff member
Longtime User
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:
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``````
This is only useful if the exact size is really important. For example if you create a ruler app.

#### Peter Simpson

##### Expert
Longtime User
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:
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``````
This is only useful if the exact size is really important. For example if you create a ruler app.

This will definitely come in handy one day.

Cheers...

• wonder

#### wonder

##### Expert
Longtime User
Thank you for the clarification, Erel.
I want to experiment with a button that remains the same physical size independently of the device.

#### ArminKH

##### Well-Known Member
As @Erel said the result for my device is about 4.58 but when i measure my device's diameter by using real ruler(From top corner to bottom corner(above navbar)) the result is 5.31 inches
my phone is huawei g610(named 5")
I set #FullScreen to true and #IncludeTitle to false

#### incendio

##### Well-Known Member
Longtime User
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:
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``````
This is only useful if the exact size is really important. For example if you create a ruler app.

Tested on Nexus 7, it returns 7.668"
Shouldn't it returns 7" ?

#### Erel

##### B4X founder
Staff member
• 