I am trying to achieve some text layout in Android a bit like float="right" in HTML. I have two paragraphs of text that can be found in a specific area of ββthe screen. I would like one of them to be left-aligned in a TextView, and one of them to be right-aligned, like this (where | at both ends is a container container): -
| First text item label |
It still sounds simple so far: I could do it with two TextView in RelativeLayout , right - with setting layout_alignParentRight="true" or layout_gravity="right" . But there is a case where the left text is too long to fit into the remaining space. With RelativeLayout it will overlap the right text, but I want it to break into two lines in this case: -
| This text is way too long | | label |
and similarly, if the left text spills over multiple lines, I want the right text to fit on the same line, if possible: -
| This text doesn't fit on | | one line label |
Since the View in Android is always rectangular, it seems that it would be impossible to make this last example work with two TextView , even if I wrote a custom Layout . I looked with Spannable so that I could fit all the text into one TextView , but again, AlignmentSpan is a ParagraphStyle , so it doesn't look like it can put the label on the same line as the left text. Is there any other range of text that I can use to achieve this, or even a completely different method?
At the moment, it seems to me that I will either have to put the text in HTML, or use a WebView (not very good, since the view should go in the list item) or write a custom TextView widget.
source share