Friday, 27 January 2012

Android: getting text to roll (marquee animate) in TextView

Set the following TextView properties in your xml layout file…

<TextView
 …
 android:id="@+id/myTextView"
 android:singleLine="true"
 android:ellipsize="marquee"
 android:marqueeRepeatLimit="marquee_forever"
 android:focusable="true"
 android:focusableInTouchMode="true"
 … />

… and now whenever the width of the text in the TextView is longer than the width of the TextView itself, the text will roll right to left along the TextView repeatedly. The number of times the animation repeats is determined by the integer value you set marqueeRepeatLimit to.

Note that sometimes the above is not sufficient and you need to make the following call in your code:
myTextView.setSelected(true);

Done!

2 comments:

Unknown said...

Good. it worked :)

Anonymous said...

the effect is very slow,how to speedup the mrquee effect?