Below is my full project. I would like to use ‘CENTER’ for ‘World Cup 2018’ in cvs.DrawText line, but the only way I can do it is to manipulate the position x and use LEFT. How can I use ‘CENTER’ and achieve a horizontally centered text. I only want to make use of the core lib. I do not wish to use XUI lib.
Thank you
Thank you
B4X:
Sub Activity_Resume
CreateBitmap
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then Activity.Finish
End Sub
Sub Activity_Create(FirstTime As Boolean)
End Sub
Sub CreateBitmap As Canvas
Dim bmp As Bitmap
bmp.InitializeMutable(200dip, 200dip)
Dim cvs As Canvas
cvs.Initialize2(bmp)
Dim r As Rect
r.Initialize(0, 0, bmp.Width, bmp.Height)
cvs.DrawRect(r, Colors.Transparent, False, 5dip)
DrawBitmap(cvs, LoadBitmap(File.DirAssets, "worldcuprussia2018.png"))
cvs.DrawText("World Cup 2018",0,cvs.Bitmap.Height/2,Typeface.DEFAULT_BOLD,12,Colors.blue,"CENTER")
' cvs.DrawText("World Cup 2018",0,cvs.Bitmap.Height/2,Typeface.DEFAULT_BOLD,12,Colors.blue,"LEFT")
Activity.SetBackgroundImage(cvs.Bitmap)
Return cvs
End Sub
Sub DrawBitmap (cvs As Canvas, bmp As Bitmap)
Dim r As Rect
r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
cvs.DrawBitmap(bmp, Null, r)
End Sub