How to wrap text in textview in Android

Constraint Layout

<TextView
android:id="@+id/some_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"

app:layout_constraintLeft_toLeftOf="@id/textview_above"
app:layout_constraintRight_toLeftOf="@id/button_to_right"/>
  • Ensure your layout width is zero
  • left / right constraints are defined
  • layout height of wrap_content allows expansion up/down.
  • Set android:maxLines="2" to prevent vertical expansion (2 is just an e.g.)
  • Ellipses are prob. a good idea with max lines android:ellipsize="end"

0dp width allows left/right constraints to determine how wide your widget is.

Setting left/right constraints sets the actual width of your widget, within which your text will wrap.

Constraint Layout docs

Leave a Comment