Can't Draw Line on ScrollView...

sconcequence

Member
Licensed User
Longtime User
I have implemented a ScrollView with a series of textedit's and labels, along with a button. I wish to draw a line in reference to one of the edit boxes (we will call this edit box hkText). I wish the line to separate the hk edit box from the edit box above it. I use the following code in Activity_Create to no avail:

ScrollView1.Initialize(700dip)
Activity.AddView(ScrollView1, 0, 0, 100%x, 100%y)
ScrollView1.Panel.LoadLayout("Main")
seperator.Initialize(ScrollView1.Panel)
y1 = (hkText.Top - 30)
y2 = (hkText.Top - 30)
seperator.DrawLine(0, y1, 100%x, y2, Colors.White, 10dip)

It always gives me an error message saying the width and height must be greater than 0. If I use Activity as the seperator.Initialize target, I see nothing.

Also, I wish it to be quite a thin line, but I wanted to make sure I could see it during tests.

Also, I wish the line to be relative to my edit box in both horizontal and vertical orientations with the two different resolutions. How do I accomplish this?

Thanks in advance.
 

klaus

Expert
Licensed User
Longtime User
You must add following lines:
B4X:
    ScrollView1.Panel.Width = 100%x
    ScrollView1.Panel.Height = 700dip
And put the drawing statement in the Activity_Resume routine.

The code below works:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim scvTest As ScrollView
    Dim cvsTest As Canvas
    Dim edtTest1, edtTest2 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    scvTest.Initialize(700dip)
    Activity.AddView(scvTest,0,0,100%x,100%y)
    
    scvTest.Panel.Width = 100%x
    scvTest.Panel.Height = 700dip
    cvsTest.Initialize(scvTest.Panel)
    
    edtTest1.Initialize("edtTest1")
    Activity.AddView(edtTest1,20dip,50dip,150dip,60dip)
    edtTest2.Initialize("edtTest2")
    Activity.AddView(edtTest2,20dip,120dip,150dip,60dip)
End Sub

Sub Activity_Resume
    Dim x1, x2, y1 As Float

    x1 = edtTest1.Left
    x2 = x1 + edtTest1.Width
    y1 = (edtTest2.Top + edtTest1.Top + edtTest1.Height)/2
    cvsTest.DrawLine(x1,y1,x2,y1,Colors.Red,1)
End Sub
Best regards.
 
Upvote 0
Top