I like to think my title question is adequate, but the details are:
I have long strings (sentences in a story) to display and want it displayed in a number of textviews, with only one line in a box. If the string is too long, I want to truncate at a space or punctuation mark, then display the rest in another textview (or views if the string is really long). My display would have many textview, each with one piece of the string.
So, the question: how can I truncate a string at the end of a textview but not before? I do not know how many characters per line.
Second question: how do I capture the remaining piece of sentence and display it in the next textview?
The idea is to have a line of a complete sentence and a translation of the sentence appearing in the line below. If the sentence is longer than a single line, the truncated first part will have a truncated, translated line below it, then the remaining part of the original sentence below that, then the remaining part of the translated sentence below that. So, alternating lines of English text and Spanish text displayed.
For the line breaks, I suggest setting up a TextView that has the width of your on-display TextViews with wrap_content
for its height. This will be an internal TextView that is for processing only and not for display. You will need to get the TextView to measure itself. This can get you started. Of course, if the text is already displayed on-screen, you can just use that TextView.
Once the view is measured, you can get its internal layout which most likely is a StaticLayout. (You can also use StaticLayout directly without the TextView.) Since the StaticLayout is a representation of the text display by the view and are the same lines of text that would display in the TextView, you can move them over directly to single-line, on-screen TextViews as long as those TextViews have the same characteristics as your internal one. StaticLayout has methods to retrieve individual lines of text.
There are details that you will have to work through, but that is the gist.
Update: I took the liberty of making a small demo app. This app takes a paragraph of text and splits it into the constituent lines. Those lines are then displayed on-screen with the original paragraph as seen below: