I have a multi line text view set to android:layout_width="wrap_content"
that, when rendered, takes all available width of the parent. When the text can fit on one line, the wrap_content
works fine, but at two or more lines, the text view seems to match the parents width, leaving what looks like padding on either side.
Because the text can not fit on one line, is the text view assuming to require all available width? I want the view to be bounded by the smallest possible dimensions.
Any ideas?
For reference, here is layout definition:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:singleLine="false"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@color/white"
android:gravity="center_horizontal"
/>
A little bit optimized solution for the accepted answer above:
I had the same problem also... You may use custom TextView with overridden method onMeasure() where you calculate the width: