Wrapping multi-line text in TextView - Android

I have a multi-line TextView with the property layout_width = "wrap_content". The problem is when the TextView actually becomes multi-line, then this property just doesn't work. How can I fix this behavior?

Here is an illustration:

enter image description here

XML:

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" android:focusable="false" android:textSize="16.5dip" android:padding="2dip" android:lineSpacingMultiplier="1.1" /> 
+4
source share
1 answer

It seems that you are using the parent view (ViewGroup), where you defined the background for your field. You just need to define a background for you TextView instead of ViewGroup. So, do not use the background in your ViewGroup, try using it in a text view. For instance:

 <FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" android:focusable="false" android:textSize="16.5dip" android:padding="2dip" android:lineSpacingMultiplier="1.1" android:background="@drawable/background_box" /> </FrameLayout> 
-1
source

All Articles