Android
Ellipsize
TextView
UI Development
Android Development

What does ellipsize mean in android?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In Android, ellipsize controls how a TextView shortens text that does not fit in the available display area. Instead of letting the text overflow or wrap forever, Android can replace part of the text with an ellipsis so the most useful portion remains visible.

What ellipsize Actually Does

The term comes from "ellipsis," meaning the three-dot truncation marker. In Android, it tells a TextView where to place that truncation when the text is longer than the view can display.

A simple example:

xml
1<TextView
2    android:layout_width="200dp"
3    android:layout_height="wrap_content"
4    android:maxLines="1"
5    android:ellipsize="end"
6    android:text="This is a very long title that will not fit on one line" />

With end, Android keeps the start of the text and truncates the tail with an ellipsis when needed.

Common ellipsize Modes

The most common values are:

  • 'end'
  • 'start'
  • 'middle'
  • 'marquee'

Each changes where the hidden text is removed.

end is the most common and is usually right for titles or labels.

start keeps the end visible and hides the beginning, which can help when suffixes matter more than prefixes.

middle keeps both ends visible while cutting out the center, which is useful for file paths, hashes, or identifiers.

marquee scrolls the text instead of replacing the hidden portion with a static ellipsis.

Width and Line Count Matter

ellipsize only activates when the view is constrained. If the TextView is free to grow, there is nothing to truncate.

That is why ellipsize is usually combined with:

  • a limited width
  • 'maxLines="1" for single-line truncation'
  • sometimes maxLines greater than one for controlled multi-line cases

Programmatically, the same idea looks like:

kotlin
textView.maxLines = 1
textView.ellipsize = TextUtils.TruncateAt.END

Without width or line constraints, it can look like ellipsize is broken when the layout simply has no reason to use it.

marquee Needs Extra Setup

marquee is the special case. It usually needs the view to be single-line and selected before the scrolling effect appears.

kotlin
textView.maxLines = 1
textView.ellipsize = TextUtils.TruncateAt.MARQUEE
textView.isSelected = true

This catches many developers because setting only ellipsize="marquee" is often not enough.

Choosing the Right Mode

A practical rule is:

  • use end for most normal labels
  • use start when the suffix is more important than the prefix
  • use middle for technical strings where both ends matter
  • use marquee sparingly because moving text can hurt readability

The correct choice depends on which part of the text the user needs most.

Programmatic Configuration

You do not have to set ellipsize only in XML. The same behavior can be configured in code:

kotlin
textView.maxLines = 1
textView.ellipsize = TextUtils.TruncateAt.MIDDLE

This is useful when a screen changes its truncation strategy dynamically, such as showing full titles in one layout state and compact identifiers in another.

Common Pitfalls

Setting ellipsize without constraining width or line count leaves the view nothing to truncate, so the attribute appears ineffective.

Expecting marquee to work without extra setup is a common source of confusion because it requires more than just the XML value.

Choosing middle or start without thinking about readability can produce text that feels unnatural for ordinary titles.

Testing only with short sample strings can hide truncation issues that appear immediately with realistic production content.

Assuming ellipsize is about text wrapping rather than truncation leads to incorrect layout expectations.

Summary

  • 'ellipsize controls how Android truncates text that does not fit.'
  • The common modes are start, middle, end, and marquee.
  • 'end is the usual choice for ordinary labels and titles.'
  • Width and line constraints are required for truncation to happen.
  • 'marquee needs additional setup and should be used carefully.'

Course illustration
Course illustration

All Rights Reserved.