In a ConstraintLayout
, I have 2 TextView
's side-by-side, and I want the right one to wrap text when it becomes too long so that it stays on the right of the left TextView
, and doesn't overflow the container. Here is the code I have now:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10sp">
...
<TextView
android:id="@+id/buildingTypeLabel"
style="@style/FormLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5sp"
android:paddingBottom="5sp"
android:text="@string/reference_view_building_type"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/dateLabel"
tools:text="Type de bâtiment" />
<TextView
android:id="@+id/buildingType"
style="@style/FormValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
app:layout_constraintBaseline_toBaselineOf="@id/buildingTypeLabel"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="@+id/buildingTypeLabel"
app:layout_constraintTop_toBottomOf="@id/date"
tools:text="Bâtiments gouvernementaux" />
...
</androidx.constraintlayout.widget.ConstraintLayout>
But instead of putting text text on 2 lines in the right TextView
, it overflows on the right:
Note that I have tried to add app:layout_constrainedWidth="true"
to the right TextView
, but it doesn't change anything.
How can I strictly enforce the right and left contraints of that TextView
and have it wrap text to have a smaller width when needed?