Ellipsize not working with side by side text view in XML

28 views Asked by At

mock

enter image description here

Trying to build something like this in a Constraint layout. Both textviews are side by side that are too long and should be ellipsized. Setting the layout_width to 0dp would stretch out the TextViews and I do not want that. When I set the layout_width to wrap_content, only the first textView collapses. The constraint is also not working properly if the second textview is too long, it would push the first textview out of bound. What can I do here?

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/your_image"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="16dp"
    android:textSize="10sp"
    app:layout_constraintStart_toEndOf="@+id/imageView1"
    app:layout_constraintEnd_toStartOf="@id/textView2"
    app:layout_constraintTop_toTopOf="@+id/parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constrainedWidth="true"
    app:layout_constraintHorizontal_chainStyle="packed"
    android:ellipsize="end"
    android:maxLines="1"
    android:text="I choose basketball class today. " />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="4dp"
    android:textSize="9sp"
    app:layout_constraintStart_toEndOf="@+id/textView1"
    app:layout_constraintTop_toTopOf="@+id/textView1"
    app:layout_constraintEnd_toStartOf="@+id/imageView2"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constrainedWidth="true"
    app:layout_constraintHorizontal_chainStyle="packed"
    android:ellipsize="end"
    android:maxLines="1"
    android:text="I choose baseball class today." />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/your_image"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
1

There are 1 answers

3
Ranjithkumar On

Yes, this is the known issue in Android

Try with singleLine, it will work

android:singleLine="true"