function and usage of text switcher (Textswitcher)

Source: Internet
Author: User

Textswitcher integrates Viewswitcher, so it has the same features as Viewswitcher: You can use animation effects when switching view components. Similar to Imageswitcher, the use of Textswitcher also requires setting up a viewfactory. Unlike Imageswitcher, the Viewfactory Makeview () method required by Textswitcher must return a TextView component.

<textswitcher is a bit like the TextView, which can be used to display text content, except that the textswitcher effect is more dazzling, which specifies the animation effect when the text is toggled. >

Not much to say, directly on the code. The interface layout file is as follows:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent " >    <!--define a textswitcher, and develop a text toggle animation effect--    <textswitcher        android:id= "@+id/textswitcher"        android:layout_width= "wrap_content"        android:layout_height= "wrap_content"        android:textalignment= " Center "        android:layout_centerhorizontal=" true "        android:layout_centervertical=" true "        Android: Inanimation= "@android: Anim/slide_in_left"        android:outanimation= "@android: Anim/slide_out_right"         Android:onclick= "Next"        >    </TextSwitcher></RelativeLayout>
a textswitcher is defined in the layout file above and an animated effect is specified for the text toggle, and the activity is then set viewfactory for the Textswitcher. The Textswitcher can work properly.

Here is the activity code:

/** * Textswitcher Practice. * @author Peter. * */public class Mainactivity extends Activity {    private textswitcher textswitcher;        Text to display    string[] STRs = new string[]    {"One", "a", "     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 Magenta tv.settextcolor (color.magenta); return TV;}});        Call the next method to display the next string        next (null);    } event handler that controls the display of the next string public void Next (View source) {textswitcher.settext (strs[curstr++% strs.length]);}}

Function and usage of text switcher (Textswitcher)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.