Android Question drawing lines on canvas

DPaul

Active Member
Licensed User
Longtime User
Hi,

I am observing a behaviour i cannot explain.
Maybe it's illegal syntax, but i get no errors, only wrong results :-(

This line does what i expect it to do:
cvsGraph.DrawLine(213dip, 325dip, 200dip, 1dip, Colors.red, BR * 1dip)
but, my line starts from a calculated point, so i do this:
cvsGraph.DrawLine((200 + x) * 1dip, 325dip, 200dip, 1dip, Colors.red, BR * 1dip)

And even if x = 13, it produces an unwanted result.
Am i not allowed to insert a calculation ?

edit: if i add the 200 to x before the drawing :
cvsGraph.DrawLine((x * 1dip, 325dip, 200dip, 1dip, Colors.red, BR * 1dip)
doesn't work either, although the one at the end does work.

thanks,
Paul
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

You should never use x * 1dip. The 'dip' unit is a shorthand syntax for DipToCurrent keyword. It returns an Int.
So if the scale is 1.5 for example it will return 1.

The correct solution is:
B4X:
cvsGraph.DrawLine (DipToCurrent(200 + x), 325dip, 200dip, 1dip, Colors.Red, DipToCurrent(BR))
'or
Dim scale As Double = 100dip / 100
cvsGraph.DrawLine((200 + x) * scale, 325dip, 1dip, Colors.Red, BR * scale)
 
  • Like
Reactions: udg
Upvote 0

klaus

Expert
Licensed User
Longtime User
I think that my remark was not clear.
In this line
cvsGraph.DrawLine((200 + x) * scale, 325dip, 1dip, Colors.Red, BR * scale)
200 and x are, what i call, dip values.
To get the pixel values, as you say, they must be scaled.
My question is: Isn't x calculated in pixel values?
 
Upvote 0
Top