<p>This article is about how to work with Android TextView ellipsize property.</p> 
 
 
 
<h3><span style="color: #000080;"><strong>Android Ellipsize</strong></span></h3> 
<p>Android TextView <strong><span style="color: #008000;">ellipsize</span></strong> property Causes words in the text that are longer than the view&#8217;s width to be ellipsized ( means to shorten text using an <strong><span style="color: #008000;"><a style="color: #008000;" href="http://en.wikipedia.org/wiki/Ellipsis" rel="noreferrer">ellipsis</a></span></strong>, i.e. three dots &#8230;) instead of broken in the middle to fit it inside the given view.</p> 
<h3><span style="color: #000080;"><strong>Ellipsize property values</strong></span></h3> 
<p class="p1">You can use the following values for ellipsize property:</p> 
<h4 class="p2"><span style="color: #000080;"><b>Ellipsize end</b></span></h4> 
<p class="p1">This will truncate your text from the end and put three dots at the end. </p> 
<p><img class="aligncenter wp-image-2631" src="https://c1ctech.com/wp-content/uploads/2021/06/Screenshot_1624957158-e1624962592749.png" alt="" width="379" height="367" /></p> 
<h5 class="p1"><strong><span style="color: #0000ff;">XML</span></strong></h5> 
<p class="p1">Set <strong><span style="color: #0000ff;">maxLines</span></strong> to 1 and set <span style="color: #0000ff;"><strong>ellipsize</strong></span> to <span style="color: #008000;"><strong>&#8220;end&#8221;</strong></span></p> 
<pre><;TextView<br />android:id="@+id/textView"<br />android:layout_width="0dp"<br />android:layout_height="wrap_content"<br />android:layout_margin="20dp"<br /><span style="color: #008000;"><strong>android:ellipsize="end"</strong></span><br /><span style="color: #008000;"><strong>android:maxLines="1"</strong></span><br />android:text="The quick brown fox jumps over the lazy dog."<br />android:textColor="@android:color/holo_red_dark"<br />android:textSize="25sp"<br />android:textStyle="bold"<br />app:layout_constraintBottom_toBottomOf="parent"<br />app:layout_constraintLeft_toLeftOf="parent"<br />app:layout_constraintRight_toRightOf="parent"<br />app:layout_constraintTop_toTopOf="parent"/>;</pre> 
<h5 class="p1"><span style="color: #0000ff;"><strong>Kotlin Code</strong></span></h5> 
<p class="p1">Find the textview. Then <span style="color: #0000ff;"><b>setMaxLines</b></span> to 1 and <span style="color: #0000ff;"><b>setEllipsize</b></span> to <span style="color: #008000;"><b>TextUtils.TruncateAt.END</b></span>.</p> 
<pre>textView.ellipsize = TextUtils.TruncateAt.END<br />textView.maxLines = 1</pre> 
<h4 class="p2"><strong><span style="color: #000080;">Ellipsize start</span></strong></h4> 
<p class="p1">This will keep the ending portion of your text and replace the starting part with three dots.</p> 
<p><img class="wp-image-2633 aligncenter" src="https://c1ctech.com/wp-content/uploads/2021/06/Screenshot_1624957663-e1624965022816.png" alt="" width="458" height="409" /></p> 
<h5 class="p1"><strong><span style="color: #0000ff;">XML</span></strong></h5> 
<p class="p1">Set <strong><span style="color: #0000ff;">singleLine</span></strong> to &#8220;<strong><span style="color: #008000;">true&#8221;</span></strong> and <span style="color: #0000ff;"><strong>ellipsize</strong></span> to <strong><span style="color: #008000;">&#8220;start&#8221;</span></strong>.</p> 
<pre><;TextView<br />android:id="@+id/textView"<br />android:layout_width="0dp"<br />android:layout_height="wrap_content"<br />android:layout_margin="20dp"<br /><span style="color: #008000;"><strong>android:ellipsize="start"</strong></span><br /><span style="color: #008000;"><strong>android:singleLine="true"</strong></span><br />android:text="The quick brown fox jumps over the lazy dog."<br />android:textColor="@android:color/holo_red_dark"<br />android:textSize="25sp"<br />android:textStyle="bold"<br />app:layout_constraintBottom_toBottomOf="parent"<br />app:layout_constraintLeft_toLeftOf="parent"<br />app:layout_constraintRight_toRightOf="parent"<br />app:layout_constraintTop_toTopOf="parent"/>;</pre> 
<h5 class="p1"><strong><span style="color: #0000ff;">Kotlin Code</span></strong></h5> 
<p class="p1">Find the textView, set <strong><span style="color: #0000ff;">singleLine,</span></strong> and then set the <strong><span style="color: #0000ff;">ellipsize</span></strong> to <span style="color: #008000;"><b>TextUtils.TruncateAt.START</b></span></p> 
<pre>textView.ellipsize = TextUtils.TruncateAt.START<br />textView.isSingleLine = true</pre> 
<h4 class="p2"><span style="color: #000080;"><b>Ellipsize middle</b></span></h4> 
<p class="p1">This will keep the starting and ending of the text and place three dots in the middle. </p> 
<p><img class="wp-image-2632 aligncenter" src="https://c1ctech.com/wp-content/uploads/2021/06/Screenshot_1624957454-e1624965364485.png" alt="" width="518" height="458" /></p> 
<h5 class="p1"><span style="color: #0000ff;"><strong>XML</strong></span></h5> 
<p class="p1">Set <strong><span style="color: #0000ff;">singleLine</span></strong> to <strong><span style="color: #008000;">true</span></strong> and <span style="color: #0000ff;"><strong>ellipsize</strong></span> to <strong><span style="color: #008000;">&#8220;middle&#8221;</span></strong>.</p>
<!-- WP QUADS Content Ad Plugin v. 2.0.98.1 -->
<div class="quads-location quads-ad2" id="quads-ad2" style="float:none;margin:0px;">

</div>
 
<pre><;TextView<br />android:id="@+id/textView"<br />android:layout_width="0dp"<br />android:layout_height="wrap_content"<br />android:layout_margin="20dp"<br /><span style="color: #008000;"><strong>android:ellipsize="middle"</strong></span><br /><span style="color: #008000;"><strong>android:singleLine="true"</strong></span><br />android:text="The quick brown fox jumps over the lazy dog."<br />android:textColor="@android:color/holo_red_dark"<br />android:textSize="25sp"<br />android:textStyle="bold"<br />app:layout_constraintBottom_toBottomOf="parent"<br />app:layout_constraintLeft_toLeftOf="parent"<br />app:layout_constraintRight_toRightOf="parent"<br />app:layout_constraintTop_toTopOf="parent"/>;</pre> 
<h5 class="p1"><strong><span style="color: #0000ff;">Kotlin Code</span></strong></h5> 
<p class="p1">Find the textView, set <strong><span style="color: #0000ff;">singleLine </span></strong><span style="color: #0000ff;"><span style="color: #000000;">to</span></span><span style="color: #008000;"><strong> &#8220;true&#8221;</strong></span> set the <strong><span style="color: #0000ff;">ellipsize</span></strong> to <span style="color: #008000;"><b>TextUtils.TruncateAt.MIDDLE</b></span></p> 
<pre>textView.ellipsize = TextUtils.TruncateAt.MIDDLE<br />textView.isSingleLine = true</pre> 
<h4 class="p2"><span style="color: #000080;"><b>Ellipsize marquee</b></span></h4> 
<p class="p1">It will make your text automatically scroll across the screen horizontally. There are no three dots involved in it.</p> 
<p><img class="alignnone wp-image-2669" src="https://c1ctech.com/wp-content/uploads/2021/07/Screenshot_1625570806-576x1024.png" alt="" width="329" height="586" /> <img class="alignnone wp-image-2670" src="https://c1ctech.com/wp-content/uploads/2021/07/Screenshot_1625570814-576x1024.png" alt="" width="332" height="590" /></p> 
<p> ;</p> 
<h5 class="p1"><strong><span style="color: #0000ff;">XML</span></strong></h5> 
<p class="p1">Set <span style="color: #0000ff;"><strong>singleLine</strong></span> to <strong><span style="color: #008000;">true </span></strong>and <strong><span style="color: #0000ff;">ellipsize</span></strong> to <strong><span style="color: #008000;">&#8220;marquee&#8221;</span></strong></p> 
<pre><;TextView<br />android:id="@+id/textView"<br />android:layout_width="0dp"<br />android:layout_height="wrap_content"<br />android:layout_margin="20dp"<br /><span style="color: #008000;"><strong>android:ellipsize="marquee"</strong></span><br /><span style="color: #008000;"><strong>android:singleLine="true"</strong></span><br />android:text="The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog."<br />android:textColor="@android:color/holo_red_dark"<br />android:textSize="25sp"<br />android:textStyle="bold"<br />app:layout_constraintBottom_toBottomOf="parent"<br />app:layout_constraintLeft_toLeftOf="parent"<br />app:layout_constraintRight_toRightOf="parent"<br />app:layout_constraintTop_toTopOf="parent" />;</pre> 
<p class="p1">You will also have to set the textView as selected using kotlin code.</p> 
<pre>textView.isSelected = true</pre> 
<h5 class="p1"><strong><span style="color: #0000ff;">Kotlin Code</span></strong></h5> 
<p class="p1">Instead of doing half thing from XML and half from kotlin code, you can make your text scroll automatically across the screen using kotlin code only.</p> 
<pre>textView.ellipsize = TextUtils.TruncateAt.MARQUEE<br />textView.isSingleLine = true<br />textView.isSelected = true</pre> 
<h4 class="p2"><span style="color: #000080;"><b>Make textView manually scrollable across the screen</b></span></h4> 
<p class="p1">The ellipsize marquee makes the text automatically scroll across the screen but if you want to give the scrolling control to the user, you can put your TextView inside a HorizontalScrollView and set the textView’s <strong><span style="color: #0000ff;">scrollHorizontally</span></strong> property to <span style="color: #008000;"><strong>&#8220;true&#8221;</strong></span>.</p> 
<pre><;HorizontalScrollView<br /> android:id="@+id/hs_textview"<br /> android:layout_width="match_parent"<br /> android:layout_height="wrap_content"<br /> android:layout_margin="10dp">;<br /><br /> <;TextView<br /> android:id="@+id/textView"<br /> android:layout_width="0dp"<br /> android:layout_height="wrap_content"<br /> android:padding="10dp"<br /> <span style="color: #008000;"><strong>android:scrollHorizontally="true"</strong></span><br /> android:text="The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog."<br /> android:textColor="@android:color/holo_red_dark"<br /> android:textSize="25sp"<br /> android:textStyle="bold"<br /> app:layout_constraintBottom_toBottomOf="parent"<br /> app:layout_constraintLeft_toLeftOf="parent"<br /> app:layout_constraintRight_toRightOf="parent"<br /> app:layout_constraintTop_toTopOf="parent"/>;<br /><br /><;/HorizontalScrollView>;</pre> 
<p><img class="aligncenter wp-image-2668 " src="https://c1ctech.com/wp-content/uploads/2021/07/manually-scrollable_textview-e1625570028266-1024x764.png" alt="" width="458" height="342" />

