Android Question Canvas DrawText Responsive Textsize?

hasexxl1988

Active Member
Licensed User
Hello,

I would like to use the Canvas.DrawText, now I have the problem that the text is shown for example on a Galaxy A3 extremely small, for a Xiaomi Mi Max 3 very large.
Other things like buttons and pictures are displayed correctly.


What am I doing wrong?

I've already tried the following:

B4X:
    b = imgPicScreen.Bitmap
    brect.Initialize(0,0,imgPicScreen.Width, imgPicScreen.Height)
    canvas.Initialize(imgPicScreen)
    canvas.DrawColor(Colors.White)
    canvas.DrawBitmap(b, Null, brect)
  
    Dim New As String
  
    New = txtTitel.Text
    New = New.ToUpperCase
    canvas.DrawText(New, pnlPicScreen.Width/2 ,pnlPicScreen.Height/2.6 ,Amatic, 3dip * 0.82%y, Colors.black, "CENTER")
    imgPicScreen.Invalidate
    pnlPicScreen.SetBackgroundImage(imgPicScreen.Bitmap)
AND

B4X:
canvas.DrawText(New, pnlPicScreen.Width/2 ,pnlPicScreen.Height/2.6 ,Amatic, 100%y / 3, Colors.black, "CENTER")

canvas.DrawText(New, pnlPicScreen.Width/2 ,pnlPicScreen.Height/2.6 ,Amatic, 100%x / 3, Colors.black, "CENTER")

canvas.DrawText(New, pnlPicScreen.Width/2 ,pnlPicScreen.Height/2.6 ,Amatic, pnlPicScreen.Width/5 , Colors.black, "CENTER")
pnlpicscreen and imgpicscreen is in the Example (Landscape) mode Width = Height

Textposition is Correct. Only the size is always wrong

I have been looking for a solution for 5 hours.
 

hasexxl1988

Active Member
Licensed User
Don't use dip units for font sizes. The sizes are scaled automatically.

%y / %x / View.Width / View.Height are also scaled. So you should divide them with the scale:
B4X:
canvas.DrawText(New, pnlPicScreen.Width/2 ,pnlPicScreen.Height/2.6 ,Amatic, pnlPicScreen.Width/5 / GetDeviceLayoutValues.Scale , Colors.black, "CENTER")
Very Thanks Erel :D
 
Top