1

Android TextView と ellipsize 属性で奇妙な動作を発見しました。テキストが長く、楕円サイズ属性が適用されている場合、テキストの元の位置が失われ、テキストが少し上に表示されます。

はい、プログラムで解決できますが、バグなのか、何か間違っているのか知りたいです。

それをテストするための非常に簡単な例。2 つの textview のテキストを変更して、テキストが省略されているか、最後のスクリーンショットに表示されているように表示されないようにします。スクリーンショットを比較すると、問題が表示されます。

「dp」と「sp」でテストして、別の動作になるかどうかを確認しました。しかし、そうではありません。

<?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>

ブロックの色の下の短いテキストは完全に接着されています

長い文字列でテキストを変更するだけで、テキストが完全に接着されない

解決:

解決策は、属性「singleLine」を使用することです。その後、問題は解消されます。しかし、AndroidStudioは「singleLineは非推奨です」と言っています。

4

1 に答える 1