I am creating a chat bubble and I noticed that when you have a TextView with text that spans multiple lines the width of the box locks to the (in this case) maxWidth. This may cause a gap on the right side:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="100dp"
android:padding="4dp"
android:text="this is a pretty short sentence"/>
As you can see there is a big white gap on the right. Without the maxWidth it fits on one line and it fits snugly:
How do I make it so that when the text spans multiple lines the box still tightly hugs the text? I've tried lots of things, but is this even possible?
Desired result:
update:
android:justificationMode="inter_word"
Results in the text fitting the box instead of the box fitting the text, which is way uglier:
Turns out it's easy to fix by subclassing TextView and overriding onMeasure(). It even works in the Layout Editor. Also performance is no issue at all: