Android Question [SOLVED] Why is my line not appearing?

alexwekell

Member
Licensed User
Longtime User
My code for drawing everything:

B4X:
Sub Activity_Create(FirstTime As Boolean)
If File.Exists(File.DirDefaultExternal, "newsettings2.txt") = False Then
              StartActivity(directions)
        File.OpenOutput(File.DirDefaultExternal, "newsettings2.txt", False)
        Else
        End If
                           
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")   
Activity.AddMenuItem("Live mode","LiveMode")

hiddenet.Initialize("")
Activity.AddView(hiddenet, 10000000dip, 100000dip, 100000dip, 10000dip)

card1.Initialize("")
card2.Initialize("")

SetNinePatchDrawable(card1, "label_bg")
SetNinePatchDrawable(card2, "label_bg")

card1.SendToBack
card2.SendToBack

Activity.AddView(card1, 10dip, 10dip, 100%x-20dip, 50%y-10dip)
Activity.AddView(card2, 10dip, 50%y+10dip, 100%x-20dip, 50%y-20dip)

Activity.LoadLayout("layout1")

button1.top = 50%y-60dip
'button1.Width = card1.Width
button1.Height = 60dip
button1.TextSize = 22
button1.Color = Colors.Transparent
button1.TextColor = Colors.rgb(66,133,244)

Button2.top = 100%y-70dip
'Button2.Width = card1.Width
Button2.Height = 60dip
Button2.TextSize = 22
Button2.Color = Colors.Transparent
Button2.TextColor = Colors.rgb(66,133,244)

rad1box.Width = 20%x
rad1box.TextColor = Colors.Gray
rad1box.top = 25%y-80dip
rad1box.Left = 20%x
rad1box.height = 40dip
rad1box.InputType = rad1box.INPUT_TYPE_NUMBERS
rad1box.TextSize = 24
rad1box.Typeface = robotolight

rad2box.Width = 20%x
rad2box.TextColor = Colors.Gray
rad2box.top = 25%y + 10dip
rad2box.Left = 20%x
rad2box.height = 40dip
rad2box.InputType = rad2box.INPUT_TYPE_NUMBERS
rad2box.TextSize = 24
rad2box.Typeface = robotolight

edittext1.Initialize("edittext1")
Activity.AddView(edittext1,0dip,0dip,0dip,0dip)
edittext1.BringToFront
edittext1.Width = 120dip
edittext1.TextColor = Colors.Gray
edittext1.top = card2.top + 60dip
edittext1.Left = 40dip
edittext1.ForceDoneButton = True
edittext1.height = 40dip
edittext1.InputType = rad2box.INPUT_TYPE_NUMBERS
edittext1.TextSize = 24
edittext1.Typeface = robotolight
edittext1.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL

'Label2.top = rad2box.top-43dip
'Label2.TextColor = Colors.LightGray
'Label2.TextSize = 30
'Label2.Typeface = robotolight
'Label2.Left = 50%x

Dim equallabel2 As Label
equallabel2.Initialize("")
Activity.AddView(equallabel2, 0dip, 0dip, 30dip, 30dip)
equallabel2.Text = "="
equallabel2.top = 25%y-30dip
equallabel2.TextColor = Colors.LightGray
equallabel2.TextSize = 30
equallabel2.Typeface = robotolight
'equallabel2.Left = 190dip
equallabel2.Left = 50%x

Dim degsymbol As Label
degsymbol.Initialize("")
Activity.AddView(degsymbol, 0dip, 0dip, 20dip, 20dip)
degsymbol.Text = "°"
degsymbol.Left = edittext1.Left+ 100dip
degsymbol.top = edittext1.top
degsymbol.TextSize = 24
degsymbol.textColor = Colors.Gray
degsymbol.Typeface = robotolight

Label3.top = 25%y-30dip
Label3.TextColor = Colors.Gray
Label3.TextSize = 30
Label3.Left = 60%x
Label3.Width = 150dip
Label3.Typeface = robotolight
Label3.Gravity = Gravity.LEFT

Dim label5 As Label
label5.Initialize("")
Activity.AddView(label5, 0dip, 0dip, 10dip, 10dip)
label5.top = card2.top+43dip
label5.TextColor = Colors.LightGray
label5.TextSize = 30
label5.Typeface = robotolight
label5.Left = 190dip

label4.top = card2.top+140dip
label4.TextColor = Colors.Gray
label4.TextSize = 24
'label4.Width = card2.Width
label4.Typeface = robotolight
label4.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
label4.Text = " "

radresultnum.top = card2.top+30dip
radresultnum.TextColor = Colors.Gray
radresultnum.TextSize = 24
radresultnum.Width = card2.Width
radresultnum.Typeface = robotolight
radresultnum.Left = 100dip

radresultden.top = card2.top+95dip
radresultden.TextColor = Colors.Gray
radresultden.TextSize = 24
radresultden.Width = card2.Width
radresultden.Typeface = robotolight
radresultden.Left = 100dip

Dim label9 As Label
label9.Initialize("")
Activity.AddView(label9, 0dip, 0dip, 20dip, 40dip)
label9.Text = "π"
label9.Typeface = robotolight
label9.TextColor = Colors.Gray
label9.TextSize = 24
label9.Left = radresultnum.Left + 205dip
label9.top = radresultnum.top

Dim label8 As Label
label8.Initialize("")
Activity.AddView(label8, 0dip, 0dip, 20dip, 40dip)
label8.Text = "π"
label8.Typeface = robotolight
label8.TextColor = Colors.Gray
label8.TextSize = 24
label8.Left = rad1box.Left + 20%x
label8.top = rad1box.top

c1.Initialize(card1)
c1.DrawLine(card1.Left-7dip, button1.top, 100%x-21dip, button1.top, Colors.LightGray, 1dip)
c1.DrawLine(rad2box.Left-5%x, 25%y-17dip, rad2box.Left+21%x, 25%y-17dip, Colors.LightGray, 1dip)

c2.Initialize(card2)
c1.DrawLine(card2.Left-7dip, Button2.top, 100%x-21dip, Button2.top, Colors.LightGray, 1dip)
c2.DrawLine(equallabel2.Left+30dip, 79dip, equallabel2.Left+130dip, 79dip, Colors.LightGray, 1dip)

Dim topcard As Panel
Dim bottomcard As Panel

Activity.Invalidate

End Sub

But I have no second line that appears on-top of my second button.
 

Attachments

  • Screenshot (01_07PM, Jun 09, 2014).png
    70 KB · Views: 142

klaus

Expert
Licensed User
Longtime User
There are two problems:
1) in these lines are you sure that the second you want to draw on c1 ?
B4X:
c2.Initialize(card2)
c1.DrawLine(card2.Left-7dip, Button2.top, 100%x-21dip, Button2.top, Colors.LightGray, 1dip)
c2.DrawLine(equallabel2.Left+30dip, 79dip, equallabel2.Left+130dip, 79dip, Colors.LightGray, 1dip)
2) You are drawing onto the Labels, but you use activity coordinates !?
Try this, probably not exactly the place where you want the lines, but it shows the principle:
B4X:
c2.Initialize(card2)
c2.DrawLine(card2.Left-7dip, Button2.top - card2.Top, 100%x-21dip, Button2.top  - card2.Top, Colors.LightGray, 1dip)
c2.DrawLine(equallabel2.Left+30dip, 79dip, equallabel2.Left+130dip, 79dip, Colors.LightGray, 1dip)
Why are you using Labels for the background ?
You should use Panels and add the views onto these Panels and then you can use the panel coordinates to draw the lines.
 
Upvote 0

alexwekell

Member
Licensed User
Longtime User

Well, that solved it and yeah...normally I would use panels, but this was the first app I'd ever made and I'm just making it look pretty now and refreshing the UI.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…