vxh.viet
4/17/2018 - 7:01 AM

TextView can't wrap_content in ConstraintLayout

TextView can't wrap_content in ConstraintLayout

New Solution, need ConstraintLayout 1.1.0

SOURCE

This behaviour has been fixed in version 1.1.0. Now TextView will grow if the text is too long but still respect the constraint:

We will need either app:layout_constrainedWidth=”true” or app:layout_constrainedHeight=”true”

<TextView
    android:layout_width="wrap_content" <----
    android:layout_height="wrap_content"
    android:text="Hello this is an example with constraint width"
    app:layout_constrainedWidth="true"  <----
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="@+id/guideline_50"/>

Old Solution, use the solution above instead

SOURCE, SOURCE

TextView doesn't seem to respect wrap_content inside ConstraintLayout (long text get cut off).

Solution, change with to 0dp:

android:layout_width="0dp"
app:layout_constraintWidth_default="wrap" //optional, seem to work fine without this in ConstraintLayout 1.0.2