Using TextSwitcher and ImageSwitcher with simple animation

Updated 1 September 2017

Save

Sometimes, To make the app pages look more attractive we need to apply different animations to our mobile content and for this Android provides developers two classes namely TextSwitcher and ImageSwitcher in order to have a transition animation in an Android View. TextSwitcher is specially designed to contain only TextView as a child. It is used to animate any text on the app page. Whenever the setText(CharSequence) method is called, TextSwitcher animates the current text out and animates the new text in. TextView and TextSwitcher work in a similar way. Similarly, an ImageSwitcher replaces an ImageView. It also contains only ImageView as a child and animates the views in and out.

 

Let us see the steps to implemen TextSwitcher.

First we will define our XML file which will contain a TextSwitcher. Below is a sample.xml.

 

Now in our Activity class we will initialise this TextSwitcher.

As you can see in the above code segment first we have picked the view and the set a ViewFactory on the TextSwitcher. ViewFactory actually provide the view which will be loaded when the view is changed.Below is the example code for ViewFactory.

Now we are all set. Now whenever we call the setText function of the TextSwitcher it will change the text according to the animation applied.

That’s all !!! Just by following these simple steps you can also implement ImageSwitcher.

Thank you very much. This is Vedesh Kumar signing off.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home