Android TextView clips text when setting maxlines="1" with gravity="center" and ellipsize="end"

661 Views Asked by At

When using maxLines="1" in combination with gravity="center" and ellipsize="end", the text gets clipped from the beginning.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        style="@style/TextAppearance.MaterialComponents.Body1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:gravity="center"
        android:ellipsize="end"
        android:maxLines="1"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s" />

</LinearLayout>

enter image description here

The issue gets resolved if maxLines="1" is changed to singleLine="true", but it's a deprecated attribute.

1

There are 1 best solutions below

1
On

It seems that TextAppearance.MaterialComponents.Body… sets android:letterSpacing to something more than zero. When this attribute is set to android:letterSpacing="0.0" the issue gets resolved.