as i understand from here density-independent pixel is a physical size.
Yes.
density independnt pixel means the following:
If you set the width of a view to 160dip in the Designer or in the code,
you will get a real width in device pixels which are 160 * scale.
dip is a shortcut of the DipToCurrent keyword, from the help:
DipToCurrent
Method
Scales the value, which represents a specific length on a default density device (Density = 1.0),
to the current device.
For example, the following code will set the width value of this button to be the same physical size
on all devices.
Button1.Width = DipToCurrent(100)
Note that a shorthand syntax for this method is available. Any number followed by the string 'dip'
will be converted in the same manner (no spaces are allowed between the number and 'dip').
So the previous code is equivalent to:
Button1.Width = 100dip 'dip -> density independent pixel
Returns : Int
DipToCurrent(Length As Int)
the button size was different.
How much is the difference?
This code will not solve the problem:
Dim lv As LayoutValues = GetDeviceLayoutValues
Log(lv.ApproximateScreenSize)
It gives the approximate dimension of the screen diagonal in inches, very approximate from my experience.
The AutoScale methode is based on this.
There does exist a method to get the real density of the device, accessible with the JavaObject.
Private xdpi, ydpi As Float
Private jo As JavaObject
jo = jo.InitializeContext
jo = jo.RunMethod("getResources", Null)
jo = jo.RunMethod("getDisplayMetrics", Null)
xdpi = jo.GetField("xdpi")
ydpi = jo.GetField("ydpi")
Log(xdpi & " / " & ydpi)
Log(GetDeviceLayoutValues.Scale)
Log(160 * GetDeviceLayoutValues.Scale)
On my Samsung Galaxy S8:
xdpi = 422.0302429199219
ydpi = 423.96978759765625
But GetDeviceLayoutValues.Scale = 3
Therefore the density taken into account by Android is 480, instead of 423, which makes a difference of about 12%.
This means that the physical dimensions are different on my device than on others with a real 480dpi screen, for a given dip value.
Don't mix up dpi (dots per inch) and dip (density independant pixel) !