简体   繁体   中英

Simple loop text animation android

I have a TextView with a maxWidth that I want to loop its text in an animation, if the text is too long to fit in this width.

I want this animation to be smooth, infinite, and to have a certain margin between the end of the text to the beginning of the text in the next animation phase.

For example, if my text is:

"And I think to myself what a wonderful world"

, and in a normal single-line+ellipsize TextView configuration it will look like:

[Beginning of TextView]And I think to myself wh...[End of TextView]

Then I want the text to start animating from left to right, until the whole text is shown, and then again (after a certain margin to the beginning of the text).

What is the simplest way to do this? I've looked for it but couldn't find anything promising.

You can add

android:scrollHorizontally="true"
android:ellipsize="marquee"

to your TextView

Note: for it to work, you have to select it in your code:

textView.setSelected(true);

Of course if you need something more customizable and elaborate this may not suits you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM