Batdude
Batdude

Reputation: 556

Setting Android Character Width

You can control the height of a text character, drawn into the canvas, with setTextSize(). For example, if you want text of height 8 pixels, you would write:

mPaint.setTextSize(8);

This works fairly well. However, I cannot seem to find a way to set the width. Hence a 8x12 pixel character looks exactly the same as an 12x12 character. I am using monospace font and want to carefully control the size of each character in a canvas.

Any ideas on how to set character width in pixels?

Upvotes: 1

Views: 2718

Answers (1)

matt5784
matt5784

Reputation: 3085

I believe the vertical height of the text is considered the text's "size", while the horizontal width is considered the "scale". For example, if you are drawing text onto a canvas using a Paint, the Paint has methods called getTextScaleX and setTextScaleX which you can use to:

Get [and set] the paint's horizontal scale factor for text.

Depending on how you are using the canvas these may be the methods you want to use - most other methods for text deal with horizontal text spacing rather than modifying the size of the actual characters themselves.

Upvotes: 2

Related Questions