In my application, a user enters a text. I put the text in the array and replace one of the letters of each word with a Japanese symbol in random order.
word.replace(letter, japaneseSymbol);
For example:
WoあdOne wいrdTwo wordうhree wえrdFour wordFおve.
Then I display the text in TextView:
content.setText(TextUtils.join(" ", convertedWords));
The problem is that the line-break is not displayed correctly:
WoあdOne wいrdTwo wordうhree w
えrdFour wordFおve.
I do not want to break the word. Do you have any idea how to avoid a word break?
I found a solution here - https://gamedev.stackexchange.com/questions/50547/how-to-force-a-line-break-before-the-last-word-of-a-line-reach-the-edge
public static String wrapString(String string, int charWrap) {
int lastBreak = 0;
int nextBreak = charWrap;
if (string.length() > charWrap) {
String setString = "";
do {
while (string.charAt(nextBreak) != ' ' && nextBreak > lastBreak) {
nextBreak--;
}
if (nextBreak == lastBreak) {
nextBreak = lastBreak + charWrap;
}
setString += string.substring(lastBreak, nextBreak).trim() + "\n";
lastBreak = nextBreak;
nextBreak += charWrap;
} while (nextBreak < string.length());
setString += string.substring(lastBreak).trim();
return setString;
} else {
return string;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.