Functions and usage of TextSwitcher
TextSwitcher integrates ViewSwitcher, so it has the same feature as ViewSwitcher: You can use animation effects when switching View components. Similar to ImageSwitcher, you also need to set a ViewFactory to use TextSwitcher. Unlike ImageSwitcher, The makeView () method of the ViewFactory required by TextSwitcher must return a TextView component.
Let's not talk about the code. The interface layout file is as follows:
The layout File above defines a TextSwitcher, and specifies the animation effect for text switching for this text switch. Then, the TextSwitcher can work normally as long as the Activity sets ViewFactory for this TextSwitcher.
The following is the Activity code:
/*** TextSwitcher practice. * @ author peter. **/public class MainActivity extends Activity {private TextSwitcher textSwitcher; // The text String [] strs = new String [] {"one", "two ", "three"}; private int curStr; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); textSwitcher = (TextSwitcher) findViewById (R. id. textSwitcher); textSwitcher. setFactory (new ViewFactory () {@ Overridepublic View makeView () {TextView TV = new TextView (MainActivity. this); TV. setTextSize (40); // font color: Red TV. setTextColor (Color. MAGENTA); return TV ;}}); // call the next method to display the next string next (null);} // event processing function, the control displays the next string public void next (View source) {textSwitcher. setText (strs [curStr ++ % strs. length]) ;}}