Textswitcher-text switcher

Source: Internet
Author: User

You can use imageswitcher to implement image switching. The text switching animation can also be implemented by a class called textswitcher, which inherits the viewswitcher class.

Viewswitcher
Contains only child textview. Textswitcher is used to animation the labels on the screen. When settext (charsequence) is called, textswitcher uses an animation to erase the current text and display new text content.

Package COM. shao. act; </P> <p> Import Java. util. timer; <br/> Import Java. util. timertask; </P> <p> Import android. app. activity; <br/> Import android. OS. bundle; <br/> Import android. OS. handler; <br/> Import android. OS. message; <br/> Import android. view. view; <br/> Import android. view. view. onclicklistener; <br/> Import android. view. animation. animationutils; <br/> Import android. widget. button; <br/> Import android. wi DGET. textswitcher; <br/> Import android. widget. textview; <br/> Import android. widget. viewswitcher. viewfactory; </P> <p> public class textswitcheractivity extends activity implements viewfactory {<br/>/** called when the activity is first created. */<br/> textswitcher switcher; <br/> handler; <br/> string [] resources ={< br/> "", "is a bodhi tree ,", <br/> "Xin Ru Ming Jing Tai,", <br/> "always clean,", <br/> "do not make dust. "<Br/>}; <br/> private handler mhandler = new handler () {</P> <p> Public void handlemessage (Message MSG) {<br/> switch (MSG. what) {<br/> case 1: <br/> id = next (); // update the id value <br/> updatetext (); // update the display content of textswitcherd; <br/> break; <br/>}< br/>}; <br/> int id = 0; // resource array ID; <br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> Init (); <br/> timer = new timer (); <br/> timer. scheduleatfixedrate (New mytask (), 1, 3000); // update every 3 seconds <br/>}< br/> private void Init () {<br/> switcher = (textswitcher) findviewbyid (R. id. switcher); <br/> switcher. setfactory (this); <br/> switcher. setinanimation (animationutils. loadanimation (this, android. r. anim. fade_in); <br/> switcher. setoutanimation (animationutils. loadanimation (this, android. r. anim. fade_out); <br/>}< br/> private int next () {</P> <p> int flag = ID + 1; <br/> If (flag> resources. length-1) {<br/> flag = flag-resources.length; <br/>}< br/> return flag; <br/>}< br/> private void updatetext () {<br/> switcher. settext (resources [ID]); <br/>}< br/> @ override <br/> Public View makeview () {<br/> // todo auto-generated method stub <br/> textview TV = new textview (this); <br/> TV. settext (resources [ID]); <br/> return TV; <br/>}< br/> private class mytask extends timertask {<br/> @ override <br/> Public void run () {<br/> message = new message (); <br/> message. what = 1; <br/> mhandler. sendmessage (Message); </P> <p >}< br/>}

 


Related Article

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.