I have two textViews aligned next to each other as such: Here is the image, I am not allowed to embed it for now
My current layout works fine if I try to increase the text for the first text view, it remains within the constraint as it should. Here is it how it looks and this is fine.
But when I try to do the exact opposite of this, i.e increase the width for the second textView, I expect the first one to remain in place, but the same does not happens and it overflows.It goes out of bounds like this.
So I cannot understand what is it that I am doing wrong? I want both the textViews to take whatever space is available to them within the constraints. Could someone guide me where I am going wrong? Both the textViews are chained to each other.
Here is my current XML Code.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryBackground">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.04" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.96" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.04" />
<TextView
android:id="@+id/tvStart"
style="@style/StyleRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Text A"
android:textSize="20sp"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toStartOf="@id/tvEnd"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="@id/guidelineStart"
app:layout_constraintTop_toTopOf="@id/guidelineTop" />
<TextView
android:id="@+id/tvEnd"
style="@style/StyleRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Text B Text B Text B Text B Text B T"
app:layout_constrainedWidth="true"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="@id/guidelineEnd"
app:layout_constraintStart_toEndOf="@id/tvStart"
app:layout_constraintTop_toTopOf="@id/guidelineTop" />
</androidx.constraintlayout.widget.ConstraintLayout>

Experimenting with
android:maxLength=""orandroid:maxWidth=""on first text view dynamically can give you desired result. At runtime, find the best-suitedmaxLengthandmaxWidthvalues based on the strings for two text views. Also, You can also check FlexLayout or FlowLayout if they solve your UI requirement.