Preface
This chapter is about android. widget. ViewSwitcher. The version is Android 2.3 r1. The translation is from "ivanlee". Thank you again "ivanlee "! I look forward to your participation in Android Chinese API translation, contact me over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog Garden: http://www.cnblogs.com/
Android Chinese translation group: http://code.taobao.org/project/view/404/
Body
I. Structure
Public class ViewSwitcher extends ViewAnimator
Java. lang. Object
Android. view. View
Android. view. ViewGroup
Android. widget. FrameLayout
Android. widget. ViewAnimator
Android. widget. ViewSwitcher
Known direct subclass
ImageSwitcher, TextSwitcher
Ii. Overview
An animation is displayed during conversion between two views. There is a factory class for creating these views. You can use a factory to create these views, or you can create them yourself. A ViewSwitcher can contain only two subviews and only one view can be displayed at a time.
(Note: similar to the ViewFlipper class, but this class is not commonly used. Generally, two sub-classes ImageSwitcher are used to add an animation effect when converting an image, and TextSwitcher is used to add an animation effect when converting text; for an example, see ImageSwitcher instance and TextSwitcher instance in apidemos)
Iii. Internal class
Interface ViewSwitcher. ViewFactory
Create a view in a ViewSwitcher
Iv. Constructor
PublicViewSwitcher(Context context)
Construct a new empty view converter (ViewSwitcher ).
Parameters
Context application environment (Translator's note: application context)
PublicViewSwitcher(Context context, AttributeSet attrs)
Construct an empty view converter (ViewSwitcher) that specifies the context and attribute set ).
Parameters
Context application environment (Translator's note: application context)
Attrs Attribute Set
V. Public Methods
Public voidAddView(View child, int index, ViewGroup. LayoutParams params)
Add a child view with specified layout Parameters
Parameters
Child View
Index of the subview added
Layout parameters of the params subview
Exception
IllegalStateException if the switch already contains two views.
Public ViewGetNextView()
Returns the view to be displayed next time.
Return
Next view to be displayed after the view is switched
Public voidReset()
Reset the ViewSwitcher to hide all existing views and enable the converter to play an animation before it is played.
Public voidSetFactory(ViewSwitcher. ViewFactory factory)
Set the factory for generating the two views that will be switched in the view converter. You can also call addView (android. view. View, int, android. view. ViewGroup. LayoutParams) twice to replace the factory method.
Parameters
Factory is used to generate a view factory for converter content
Vi. Supplement
Article Selection
Use of android UI ViewSwitcher (Part 2)
Android: Don't Overlook ViewSwitcher
Using a ViewSwitcher in your Android xml layouts