Reputation: 15
I have a multiline TextView for which I want to disable word wrap completely and have the sentence break at the end of the line, whichever character that might be, in the middle of the "word".
So instead of this:
| |
|Lorem ipsum dolor sit amet, consectetur |
|adipiscing elit, sed do eiusmod tempor |
|incididunt ut labore et dolore magna aliqua.|
| |
|Lorem/ipsum/dolor/sit/amet,/consectetur/ |
|adipiscing/elit,/sed/do/eiusmod/tempor/ |
|incididunt/ut/labore/et/dolore/magna/aliqua.|
| |
I want to see this:
| |
|Lorem ipsum dolor sit amet, consectetur adip|
|iscing elit, sed do eiusmod tempor incididun|
|t ut labore et dolore magna aliqua. |
| |
|Lorem/ipsum/dolor/sit/amet,/consectetur/adip|
|iscing/elit,/sed/do/eiusmod/tempor/incididun|
|t/ut/labore/et/dolore/magna/aliqua. |
| |
Replacing the regular space character with non-breaking space \u00A0
is not really a solution as far as I can tell, because line breaks happen on other characters, like slash for example, too.
I feel like I've already tried all possible combinations of values for android:breakStrategy
, android:lineBreakStyle
, android:lineBreakWordStyle
, android:singleLine
... What am I overlooking?
Originally, I have a simple TextView (inside a ScrollView if that's relevant):
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|start"
android:textSize="16sp"
android:fontFamily="monospace"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</ScrollView>
TextView#setLineBreakStyle(int)
mentions:
See the word-break property for more information.
Which in turn mentions an additional possible value "anywhere", which says:
There is a soft wrap opportunity around every typographic character unit (...) This value triggers the line breaking rules typically seen in terminals.
Which sounds exactly like what I'm looking for. But setting "anywhere" for lineBreakStyle
doesn't seem to be an option for TextView
? (Yet?)
Upvotes: 0
Views: 57