Search code examples
androidtextviewmarquee

TextView android:ellipsize="marquee" not working as expected


I have some custom elements in a ListView and each element is, up to know, just a TextView in a LinearLayout. I would like the text inside the TextView to be a single line scrolling horizontally when the text is too long. I read many posts on this and I came up with a solution that was supposed to work, but instead of having the full text scrolling I have the text cut to the length of the containing View and ended with the three dots. I don't want the three dots but the entire text needs to be scrolled.

This is the layout of the items in the list (list_item.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listItem"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/list_item_selector"
    android:orientation="horizontal"
    android:paddingBottom="7dp"
    android:paddingLeft="15dp"
    android:paddingTop="7dp" >

    <TextView
        android:id="@+id/listText"
        style="@style/Text_View_Style_White"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever" 
        android:padding="3dp"

        android:selectAllOnFocus="true"
        android:singleLine="true"
        android:textColor="@drawable/list_item_text_selector" />


</LinearLayout>

I tried also with android:focusable="true", android:scrollHorizontally="true" and android:maxLines="1" attributes but none of them is working. In the getView() method of the adapter (which extends a BaseAdapter) I use the setSelected(true) method on the TextView, before returning the View.

I can't figure out what the problem is. Any help will be highly appreciated.


Solution

  • As @iDroid Explorer pointed out, posting and accepting the answer can be of help to someone else. Adapting from my reply to Tom's comment:

    I found the solution to my problem. After some attempts I've realized that the problem was the android:selectAllOnFocus="true" line (Read @Tom's explanation for probabale reason). I just removed that line and now everything is working very well, the text is complete and scrolling like desired when it is too long for the containing view.