Preface
This chapter is about Android. widget. textswitcher. It is translated into a Text Converter Control (derived from the famous door series) and translated from madgoat. You are welcome to visit his blog: http://madgoat.cn/. thank madgoat again! I look forward to your participation in Android API Chinese translation, contact me over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Madgoat: http://madgoat.cn/
Blog: http://www.cnblogs.com
Farmer's uncle: http://www.cnblogs.com/over140/
Version
Android 2.2 r1
Body
I. Structure
Public class textswitcher extends viewswitcher
Java. Lang. Object
Android. View. View
Android. View. viewgroup
Android. widget. framelayout
Android. widget. viewanimator
Android. widget. viewswitcher
Android. widget. textswitcher
Ii. Category Overview
Viewswitcher only contains the child-type 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. (Note: Some animated effects are added when the text is changed)
Iii. Constructor
Public textswitcher (context)
Create a new blank textswitcher
Parameters
Context application context
Public textswitcher (context, attributeset attrs)
Use the provided context and attributes to create an empty textswitcher
Parameters
Context application environment
Attrs Attribute Set
Iv. Public Methods
Public void addview (view child, int index, viewgroup. layoutparams Params)
Adds a subview Based on the specified layout parameter.
Parameters
Child subview
Position of the new subview in Index
Add the layout parameters of the Child view in Params.
Throw an exception
Illegalargumentexception when the subview is not a textview instance
Public void setcurrenttext (charsequence text)
Set the text content of the currently displayed Text View. Non-animated display.
Parameters
New text to be displayed in text
Public void settext (charsequence text)
Set the text content of the next view and switch to the next view. You can exit the current text to display the next text.
Parameters
New text to be displayed in text
V. Sample Code
5.1 from apidemos> View> textswitcher
5.1.1 Java
Public class textswitcher1 extends activity implements viewswitcher. viewfactory,
View. onclicklistener {
Private textswitcher mswitcher;
Private int mcounter = 0;
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. text_switcher_1 );
Mswitcher = (textswitcher) findviewbyid (R. Id. switcher );
Mswitcher. setfactory (this );
Animation in = animationutils. loadanimation (this,
Android. R. anim. fade_in );
Animation out = animationutils. loadanimation (this,
Android. R. anim. fade_out );
Mswitcher. setinanimation (in );
Mswitcher. setoutanimation (out );
Button nextbutton = (button) findviewbyid (R. Id. Next );
Nextbutton. setonclicklistener (this );
Updatecounter ();
}
Public void onclick (view v ){
Mcounter ++;
Updatecounter ();
}
Private void updatecounter (){
Mswitcher. settext (string. valueof (mcounter ));
}
Public View makeview (){
Textview T = new textview (this );
T. setgravity (gravity. Top | gravity. center_horizontal );
T. settextsize (36 );
Return T;
}
}
5.1.2 XML
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: Orientation = "vertical">
<Button Android: Id = "@ + ID/next"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/text_switcher_1_next_text"/>
<Textswitcher Android: Id = "@ + ID/switcher"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"/>
</Linearlayout>
5.2 other examples
Http://tech.ddvip.com/2010-02/1265125017144500.html
Http://www.javaeye.com/topic/569985
6. Download
Http://download.csdn.net/source/2774515 (csdn)
End
Madgoat is very positive. After receiving the translation of this chapter, he quickly translated it with complete code and. Now he is translating the next translation. Thank you for your participation!