7

I want to know if there is any way to modify text height and width separately when drawing with canvas. To set text size you can simply do paint.setTextSize(x);but it change text size in X and Y and I need to change text size in X and Y separately as you do with paint.setTextScaleX(x);but there isn't anything like paint.setTextScaleY(y);.

Is any way to implement this or does it already exists in Android ?

Thank you

Andres
  • 6,080
  • 13
  • 60
  • 110

1 Answers1

7

There is no setTextScaleY method, because there is no need for one. setTextSize multiplies both X and Y scale factors, and setTextScaleX multiplies the X scale factor only. So you could reach any desired scaling scaleX, scaleY this way:

setTextSize(scaleY);
setTextScaleX(scaleX/scaleY); //setTextScaleX scales according to the CURRENT size (setTextScaleX(1) does nothing).
Jong
  • 9,045
  • 3
  • 34
  • 66
  • But in setTextSize I cannot put a scale 1.25 because the text is extremely small, but if I put setTextScaleX(1.25); the text is ok. I can't relate (scaleX/scaleY) because scaleY should be a number like 30 and scale X should be a number like 1.5 so it gives me a very small number and text is streched. I can't modify only X size or only Y size on this way or I am not understanding it right. – Andres Dec 12 '12 at 02:05
  • It's either you don't understand me, or I don't understand you :( What are the final scalings you want to achieve? – Jong Dec 12 '12 at 02:19
  • 3
    Nevermind I got it. To modify only Y value I do: setTextSize(actualTextSize*scaleFactor); setTextScaleX(actualXScale/scaleFactor); To modify only X value I do: setTextScaleX(actualXScale/scaleFactor); Thank you for your help ;) – Andres Dec 12 '12 at 19:08
  • Yea, that's the way to use these methods. – Jong Dec 12 '12 at 19:21