How to adjust the display of text in android to cut any letters that do not match the layout

I have several TextViews in a row and I want 1st TextView to occupy all the free space, but if the combined length of TextViews is too long to fit on one line, I want the 1st TextView to be cut off.

Regarding spare space, I set the 1st TextView layout_width to match the parent and layout_weight to 1, which works. I just can't get it to truncate extra letters so that it matches one line.

What I want is something like the following: “Text” and “Long Text”

'Text   :data'
'Long T :data'

So, “Long Text” is turned off to “Long T” to fit.

I get

'Text   :data'
'Long Text :d'

Thank!

+6
3

- :

android:singleLine="true"
android:ellipsize="start"
android:scrollHorizontally="true"
+1

fooobar.com/questions/4620988/...   ,

<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
    android:padding="8dp">

    <TextView
        android:id="@+id/leftText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="1"
        app:layout_constrainedWidth="true"
        app:layout_constraintHorizontal_bias="0"
        app:layout_constraintEnd_toStartOf="@id/rightText"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="|short destination|" />

    <TextView
        android:id="@+id/rightText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/leftText"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="|next departure|" />

</androidx.constraintlayout.widget.ConstraintLayout>
0

All Articles