I have found a strange behavior with the Android TextView and the ellipsize attribute. When the text is long and the ellipsize attribute is applied, the original position of the text is lost and the text appears a bit upper.
Yes, I can solve it programatically, but I would like to know if it could be a bug or I'm doing something wrong.
A very simple example to test it. Change the text of two textview to see the text ellipsized or not like I'm showing on the last screenshots. If you compare the screenshots you'll see the issue.
I have tested it with 'dp' and 'sp' to see if it could be a different behavior. But it isn't.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<View
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="50dp"
android:background="@android:color/holo_green_dark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23.3dp"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Hello World! (dp textSize)"
android:textColor="@android:color/black"
android:textSize="25dp" />
<View
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="150dp"
android:background="@android:color/holo_blue_dark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="123.2dp"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Hello World! (sp textSize)"
android:textColor="@android:color/black"
android:textSize="25sp" />
</RelativeLayout>
Short texts under the blocks color perfectly glued
Simply changing the texts with a long string and the texts aren't perfectly glued
SOLUTION:
The solution is to use the attribute 'singleLine' and then the problem disappear. But AndroidStudio tells me 'singleLine is deprecated'.