Android Question How to draw Oval with text inside

Discussion in 'Android Questions' started by ttsolution, Jun 16, 2015.

  1. ttsolution

    ttsolution Member Licensed 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,

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

    Erel Administrator Staff Member Licensed User

    It will be easier to use a Label for this:

    [​IMG]

    [​IMG]
     
    ellpopeb4a likes this.
  3. ttsolution

    ttsolution Member Licensed 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,
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You can create such a label at runtime with ColorDrawable.
     
  5. strat

    strat Active Member Licensed User

    Using Colordrawable may be easy solution but I had already written this code:

    Code:
    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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice