ユーザ用ツール

Ellipsize

概要

TextViewなどで、画面からはみ出すような長い文字列を表示するときに、末尾などに「…」を表示する機能が、Ellipsizeであるが、単純にこれを有効にしただけでは、実際には、Ellipsizeの処理はされない。

以下に、必要と思われる設定項目を列挙しておく。

必要とされる設定項目(水平方向)

  • ellipsize
  • maxLines
  • scrollHorizontally

ellipsizeは、“none”, “start”, “middle”, “end”, そして“marquee”の中から選ぶ。水平方向の場合には、“end”を選ぶのが普通だと思われるが、自動的にスクロールして内容を表示させたい場合には“marquee”もあるだろう。

maxLinesは1に設定する。 かつてはsingleLineというbooleanのパラメタがあったが、これはdeprecatedになっているので、使用するべきではない。

そして最後の scrollHorizontallyを必ず trueにしないと、このEllipsizeの処理はなされない。多くの場合、この項目の設定忘れが、Ellipsizeされない原因だと思われる。

<TextView
        android:id="@+id/txtAuthor"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="1"
        android:scrollHorizontally="true"
        android:text="TextView" />

Androidに関してへ戻る。

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information