Android TextViewとellipsize属性で奇妙な動作が検出されました。 テキストが長く、ellipsize属性が適用されると、テキストの元の位置が失われ、テキストが少し上に表示されます。ellipsize属性が元の位置から移動したAndroid TextView
はい、私はそれをプログラム的に解決できますが、それがバグか、何か間違っているかどうかを知りたいと思います。
非常に簡単な例です。 2つのテキストビューのテキストを変更して、最後のスクリーンショットに表示されているように、テキストが省略されているかどうかを確認します。スクリーンショットを比較すると、問題が表示されます。
私は 'dp'と 'sp'でテストして、違う動作が可能かどうかを確認しました。しかし、そうではありません。
Short texts under the blocks color perfectly glued
<?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>
Simply changing the texts with a long string and the texts aren't perfectly glued
SOLUTION:
ソリューションが消え属性 '単一行' と、問題を使用することです。しかし、AndroidStudioでは、 'singleLineは非推奨です'と伝えています。
解決策は、属性 'singleLine'を使用することです。問題が解消されます。しかし、AndroidStudioでは、 'singleLineは非推奨です'と伝えています。 – aLxnophis