Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to wrap text by chars? (Not by words)

For instance:

This is foo text for wrapping text in TextView

The way that TextView wraps is:

This is foo text for
wrapping text in ...

I want this:

This is foo text for wr
apping text in TextView
like image 391
Christian Avatar asked Feb 25 '11 14:02

Christian


People also ask

How do you wrap text on Android?

Please goto "File->Settings->Editor->General" tab and check "Use soft wraps in editor". it will solve your problem.

How do I edit text wrap in text?

Select Format and then under Arrange, select Wrap Text. Choose the wrapping option that you want to apply. Tip: To change a picture or drawing object's position on the page relative to the text, select the picture or object, select Format > Position, and then select the position that you want.

What is Wraping of text?

"Wrapping text" means displaying the cell contents on multiple lines, rather than one long line. This will allow you to avoid the "truncated column" effect, make the text easier to read and better fit for printing.


2 Answers

It's a bit hacky, but you could replace spaces with the unicode no-break space character (U+00A0). This will cause your text to be treated as a single string and wrap on characters instead of words.

myString.replace(" ", "\u00A0");

like image 158
martinp Avatar answered Oct 04 '22 07:10

martinp


As I know, there is no such property for TextView. If you want to implement text wrapping by yourself, you can override TextView and use Paint's breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth) function. Note that you have to specify text size, typeface etc to Paint instance.

like image 38
Olsavage Avatar answered Oct 04 '22 05:10

Olsavage