Textswitcher of Androidui Components

Source: Internet
Author: User

Package com.gc.textswitcherdemo;/* * Text switcher (textswitcher): * 1, Textswitcher inherits Viewswitcher, so it has the same characteristics as Viewswitcher * You can use the animation effect when you switch the view component. Similar to Imageswitcher, the use of Textswitcher * also requires setting up a viewfactory. Unlike Imageswitcher, the Makeview () method required by Textswitcher must return a TextView component. * 2, Textswitcher and TextView function a bit similar, they can be used to display text content, the difference is that * textswitcher effect is more dazzling, it can specify the text switch animation effect * */import Android.os.Bundle; Import Android.app.activity;import android.graphics.color;import Android.view.menu;import Android.view.View;import Android.widget.textswitcher;import Android.widget.textview;import android.widget.viewswitcher.viewfactory;/** * * @ Author Android General * */public Class Mainactivity extends Activity {private textswitcher textswitcher;private string[] Strs=n EW string[]{"Android General", "General iOS", "General Cocos2d-x", "General"};p rivate int curstr; @Overrideprotected 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 (+); 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]);}}

The layout file is as follows:

<linearlayout 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 "    android:orientation= "vertical"       >   <!--defines a textswitcher and specifies the animation effect when text is toggled-   < Textswitcher        android:id= "@+id/textswitcher"       android:layout_width= "match_parent"       android:layout_ height= "Wrap_content"       android:inanimation= "@android: Anim/slide_in_left"       android:outanimation= "@ Android:anim/slide_out_right "       android:onclick=" Next "       />    </LinearLayout>
Effect:

Reprint Please specify source: http://blog.csdn.net/android_jiangjun/article/details/25604177

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.