Using textview in Android to realize word by word animation

preface

Android textview can only animate the entire textview, not each text. Even with textswitcher, it is difficult to achieve the effect I want.

So choose a custom one. The general idea is: inherit the ViewGroup. When setting text, each text is a textview. Start the animation of each textview at a fixed time.

Define a CTextView that inherits the ViewGroup:

Main implementation code:

A method settext (string text, final animation, animation, int duration) is provided externally. Text is the string to be displayed, animation is the animation of each character, and duration is the playback interval of character animation.

The method is implemented as follows:

CTextView is fully implemented as follows:

Then use the custom component in the layout file:

In Activity, call the setText method of CTextView and pass in the relevant parameters.

The second parameter is animation. The effect I want is from transparent to opaque, myanim xml:

If you want to realize text flying in one by one from the right:

summary

The above is the whole content of word by word animation by using textview in Android. The effect is still very good. Interested partners can practice it by themselves. If you have any questions, you can leave a message for discussion.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>