Android Question Int To DIP

LordZenzo

Well-Known Member
Licensed User
Longtime User
this simple operation generates an error in the compilation
B4X:
 LS1.Padding=Array (6.7%x ,0dip,0dip,0dip) [\CODE]

in the forum I found this solution
[CODE]
Sub IntToDIP(Integer As Int) As Int 
   Dim DIP As Int
   DIP = Integer * 1dip
   Return DIP
End Sub
[\CODE]
 

Star-Dust

Expert
Licensed User
Longtime User
To have greater precision and avoid the rounding of 1Dip, Erel suggested to work 100dip / 100.
The error is perhaps generated by the fact that you use reserved KeyWords

B4X:
Sub IntToDIP(Value As Int) As float
    Return Value*(100dip/100)
End Sub
 
Upvote 0

LordZenzo

Well-Known Member
Licensed User
Longtime User
no
this is error in the compilation

LS1.Padding=Array(IntToDIP(4%x),0dip,0dip,0dip)
javac 1.8.0_131
src\com\iliad\gilo\main.java:493: error: incompatible types: Object[] cannot be converted to int[]
parent.mostCurrent._ls1.setPadding((int[])(new Object[]{(Object)(_inttodip(anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (4),mostCurrent.activityBA))),(Object)(anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (0))),(Object)(anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (0))),(Object)(anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (0)))}));
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Try it
B4X:
Dim V as Int =IntToDIP(4%x)
LS1.Padding=Array(V,0dip,0dip,0dip)
 
Upvote 0

emexes

Expert
Licensed User
To have greater precision and avoid the rounding of 1Dip, Erel suggested to work 100dip / 100.
Whilst down in the mud of pedant detail here...

Since DIP's are defined as 160 per inch, I've been using 160DIP / 160 as the conversion factor, which likely cancels out an integer rounding based on the DIP suffix probably being equivalent to the integer operations: * DevicePPI / 160.

On the one hand, we're only talking about being one pixel out; on the other hand, sometimes one pixel errors stand out like a star in the night sky, especially if there's a line of them.
 
Last edited by a moderator:
Upvote 0
Top