简体   繁体   English

如果 android jetpack compose 中的单词太长,则用连字符打破句子行

[英]Break sentence line with hyphen if word is too long in android jetpack compose

How to break line with hyphen if word is too long to fit in.如果单词太长而无法放入,如何用连字符换行。

for example:例如:

|<----screen space----->|

"This is example of veryLongWord." // very long sentence :P

Currently sentence line break like this.

|<------screen space------>|
This is example of |<----->|empty space
veryLongWord.



I want to achieve this:

|<------screen space------>|
This is example of veryLon-
gWord.

So before anyone come to the rescue, as far as I looked into the Text() API, there is no solution for what you want out of the box.因此,在任何人前来救援之前,就我研究 Text() API 而言,没有针对您想要的开箱即用的解决方案。

Even then it does not sound like what you are looking for, the only ready to use solution I know is.即使那样,它听起来不像您正在寻找的东西,我所知道的唯一可以使用的解决方案是。

        Text(
        ...
            textAlign = TextAlign.Justify,
            softWrap = true
        ...
        )
["

if replace space to "\ ", it will work.<\/i>如果将空格替换为“\ ”,它将起作用。<\/b> cause your text to be treated as a single string.<\/i>导致您的文本被视为单个字符串。<\/b><\/p>

Text( ... text = "your text".replace(" ", "\ "), ... )<\/i> Text( ... text = "你的文字".replace(" ", "\ "), ... )<\/b><\/p>"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM