Android Question How to draw Oval with text inside

ttsolution

Member
Licensed User
Longtime User
Dear all,
I have a sub below to draw a Text as bitmap. How can we draw a Circle with number inside?

Thanks in advance for any help,

B4X:
Sub CreateBitmap(mText AsString) As Canvas
Dim bmp AsBitmap
bmp.InitializeMutable(40dip, 40dip)
DimcvsAsCanvas
cvs.Initialize2(bmp)
cvs.DrawText(mText,10dip,25dip,Typeface.DEFAULT,23, Colors.Black,"LEFT")
Returncvs
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It will be easier to use a Label for this:

SS-2015-06-16_08.19.03.png


SS-2015-06-16_08.19.42.png
 
Upvote 0

ttsolution

Member
Licensed User
Longtime User
Many thanks Erel, I could done this by adding a label from Design, but in my case I need to create this label in runtime. My App show Customers in Google Map and I wish to draw my own maker is Oval/Circle with a number inside, each customer may have different number/color based on their volume sales.

Jonh,
 
Upvote 0

strat

Active Member
Licensed User
Longtime User
Using Colordrawable may be easy solution but I had already written this code:

B4X:
Sub Button1_Click
    Dim iv As ImageView
    Dim c As Canvas
    Dim rect1 As Rect
    Dim tf As Typeface
    Dim rx1,ry1,rw,rh As Int
    Dim r_,g_,b_,clr As Int
    Dim Height_, Width_,fs As Int
    Dim lbl As Label
    Dim obj As Reflector
    fs=23 ' Font size
    tf=Typeface.DEFAULT
    lbl.Initialize("lbl")
    Activity.AddView(lbl,0,0,1,1)
    lbl.Typeface=tf
    lbl.TextSize=fs
    lbl.Text=Rnd(1,99)
    lbl.Width=-2
    lbl.Height=-2
    DoEvents
    obj.Target = lbl
    Width_ = obj.RunMethod("getWidth")
    Height_ = obj.RunMethod("getHeight")
   
    iv.Initialize("iv")
    rx1=Rnd(0,90%x)
    ry1=Rnd(0,80%y)
    rw=10%x
    rh=10%x
    r_=Rnd(0,255)
    g_=Rnd(0,255)
    b_=Rnd(0,255)
   
    Activity.AddView(iv,rx1,ry1,rw,rh)
    c.Initialize(iv)
   
    rect1.Initialize(0,0,rw,rh)
   
    c.DrawOval(rect1,Colors.RGB(r_,g_,b_),True,5dip)
    c.DrawText(lbl.Text,(rw-Width_)/2,(rh+fs)/2,tf,fs, Colors.Black,"LEFT")
End Sub
 
Upvote 0
Top