Andres
Andres

Reputation: 6200

Change text height and width separately when drawing with canvas

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

Upvotes: 7

Views: 2908

Answers (1)

Jong
Jong

Reputation: 9125

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).

Upvotes: 7

Related Questions