Is there a way to make ellipsize=”marquee” always scroll?

I finally came up against this problem today and so fired up hierarchyviewer on the Android Market application.

Looking at the title on an app’s detail screen, they use a plain old TextView. Examining its properties showed that it wasn’t focused, couldn’t be focused and was generally very ordinary — except for the fact that it was marked as selected.

One line of code later and I had it working 🙂

textView.setSelected(true);

This makes sense, given what the Javadoc says:

A view can be selected or not. Note that selection is not the same as focus. Views are typically selected in the context of an AdapterView like ListView or GridView.

i.e. When you scroll over an item in a list view (like in the Market app), only then does the now-selected text start scrolling. And since this particular TextView isn’t focusable or clickable, it will never lose its selection state.

Unfortunately, as far as I know there is no way to pre-set the selected state from the layout XML.
But the one-liner above works fine for me.

Leave a Comment