Textswitcher 's Java Doc describes itself in this way:
Specialized Viewswitcher that contains only children of type TextView. A textswitcher is useful to animate a label on screen. Whenever SetText (charsequence) is called, Textswitcher animates the current text out and animates the new text in .
So, Textswitcher:
-There is a TextView child View
-When text is updated, the old text fades out and new text fades in, rendering the animated effect of smooth transitions
How to use Textswitcher step 1th: Add Textswitcher controls in Layout
<TextSwitcher android:id="@+id/ts" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_marginTop="20dp" android:layout_weight="1" > </TextSwitcher>
2nd step: Set up a factory for the Textswitcher control (for production views)
mTs.setFactory(new TextSwitcher.ViewFactory() { @Override publicmakeView() { final TextView tv = (TextView) LayoutInflater.from( null); return tv; } });
3rd step: Setting the Fade animation
mTs.setInAnimation(AnimationUtils.loadAnimation( getApplicationContext(), android.R.anim.fade_in)); mTs.setOutAnimation(AnimationUtils.loadAnimation( getApplicationContext(), android.R.anim.fade_out));
After that, the mTs.setText(txt)
following effect is performed when the text is toggled:
Note: Full code on GITHUB
[Android] Textswitcher--What do you do?