TextView
レイアウトに がwrap_content
ありますlayout_width
。最大 15 文字に制限されているため、 を使用していますmaxLength
。
これを 3 つのドット (...) で終了する必要がありますTextView
が、これは dp で固定サイズを指定した場合のみ発生しますがlayout_width
、これは望ましくないことです。
15 番目の文字以降の文字列をトリミングして 3 つのドットを追加することでプログラム的に可能であることはわかっていますが、私はそれを XML で行うことを好みます。
テキストを 3 つのドットで終了し、wrap_content のままにする方法はありますか?
<TextView
android:id="@+id/inbox_contactName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:maxLines="1"
android:ellipsize="end"
android:singleLine="true"
android:maxLength="15"
android:textColor="#0670b4"
android:textSize="16sp" />
ベストアンサー1
これで問題は解決します。XMLellipsize
コードでプロパティを使用してください。
android:ellipsize="end" <!-- This makes the magic ... thing -->
android:maxEms="15" <!-- Limit of the Text -->
android:singleLine="true" <!-- In case if you want everything in one line -->
編集: singleLine
は非推奨代わりにを使用してくださいmaxlines="1"
。