Search code examples
androidtextviewellipsis

Marquee using maxLines


How can I have a marquee using MaxLines instead of SingleLine ?

This is my TextView :

<TextView
    android:text="bla bla bla bla bla bla"
    android:id="@+id/MarqueeText" 
    android:layout_width="30dp"
    android:layout_height="wrap_content" 
    android:singleLine="true"
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:freezesText="true">

After in my code.java I setSelected my TextView :

TextView txtView=(TextView) findViewById(R.id.MarqueeText);
txtView.setSelected(true);

The problem is android:singleLine is deprecated so I have to use android:maxLines instead but the marquee don't work with it.


Solution

  • You can try using this :

    android:maxLength = "10"
    

    OR

    After setting android:maxLines="1", you have to set your inputType too. So, set your android:inputType="text" and that should do the trick.