Android Question Adding text to the end of polylines

andyp

Member
Licensed User
Hi. So I have a map with two polylines. I wish to add some text to the end of each line (the text is a time eg 20:10hrs).

I guess I could use a two markers - but you cant have two markers open displaying text at the same time, right?

So I think that leaves using bitmaps. Any ideas how to convert times to bitmaps, and then display these?

Thank you for your help
Andrew
 

andyp

Member
Licensed User
Well, the XUI library and B4XBitmap create easily solved the issue of bitmap creation :)

One issue - when I send a text string to B4XBitmap, I want the text in the bitmap to be over two lines. I tried:

B4X:
    mystring = ("Top Line" & CRLF & "Bottom Line")

But this still created just one line of text in the bitmap (Top Line Bottom Line).

Any way to do two lines of text in one bitmap with B4XBitmap?

Thank you!
 
Upvote 0

andyp

Member
Licensed User
Hi Erel

Thank you, but could you please give a few more clues :)

Here is my current code for one line (well, trying to use CRLF to create two lines, which is not working - it creates just one line):

B4X:
Dim twolinebitmap As B4XBitmap = CreateBitmap("Top Line" & CRLF & "Bottom Line" )


Sub CreateBitmap(text As String) As B4XBitmap
 
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 50dip, 30dip)
    Dim c As B4XCanvas
    c.Initialize(p)
    c.DrawRect(c.TargetRect, xui.Color_Transparent, True, 0)
    c.DrawText(text, c.TargetRect.CenterX, c.TargetRect.CenterY + 4dip, xui.CreateDefaultBoldFont(10), xui.Color_Yellow, "CENTER")
    c.Invalidate
    Return c.CreateBitmap
 
End Sub

How would I create a bitmap with two lines of text?

I am drawing the bitmap on my gmap using Addmarker3.....

Thank you!
Andrew
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

andyp

Member
Licensed User
Hi Erel

Thank you! Updated to 7.80 and 1.5. The code seemed to be missing this line:

B4X:
Dim xui As XUI

But then all working great. Does exactly what I was looking for :)

Is there any way to set a background color?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The code seemed to be missing this line:
I usually add a global XUI variable.

Is there any way to set a background color?
B4X:
Sub CreateBitmap(text As String) As B4XBitmap
   Dim lbl As Label
   lbl.Initialize("")
   Dim xlbl As B4XView = lbl
   xlbl.SetLayoutAnimated(0, 0, 0, 200dip, 100dip)
   xlbl.Text = text
   xlbl.TextColor = xui.Color_Yellow
   xlbl.SetTextAlignment("CENTER", "CENTER")
   xlbl.Color = xui.Color_Green
   'or
   xlbl.SetColorAndBorder(xui.Color_Green, 2dip, xui.Color_Black, 5dip)
   Return xlbl.Snapshot
End Sub
 
Upvote 0
Top