Most visited

Recently visited

Added in API level 1

ViewSwitcher

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 Subclasses


ViewAnimator ,它在两个视图之间切换,并有一个从中创建这些视图的工厂。 您可以使用工厂创建视图,或者自己添加它们。 一个ViewSwitcher只能有两个子视图,其中一次只显示一个。

Summary

Nested classes

interface ViewSwitcher.ViewFactory

在ViewSwitcher中创建视图。

Inherited XML attributes

From class android.widget.ViewAnimator
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

ViewSwitcher(Context context)

创建一个新的空ViewSwitcher。

ViewSwitcher(Context context, AttributeSet attrs)

为给定的上下文和指定的set属性创建一个新的空ViewSwitcher。

Public methods

void addView(View child, int index, ViewGroup.LayoutParams params)

添加具有指定布局参数的子视图。

CharSequence getAccessibilityClassName()

返回此对象的类名称以用于辅助功能。

View getNextView()

返回要显示的下一个视图。

void reset()

重置ViewSwitcher以隐藏所有现有视图,并使其认为第一次动画尚未播放。

void setFactory(ViewSwitcher.ViewFactory factory)

设置用于创建ViewSwitcher将翻转的两个视图的工厂。

Inherited methods

From class android.widget.ViewAnimator
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public constructors

ViewSwitcher

Added in API level 1
ViewSwitcher (Context context)

创建一个新的空ViewSwitcher。

Parameters
context Context: the application's environment

ViewSwitcher

Added in API level 1
ViewSwitcher (Context context, 
                AttributeSet attrs)

为给定的上下文和指定的set属性创建一个新的空ViewSwitcher。

Parameters
context Context: the application environment
attrs AttributeSet: a collection of attributes

Public methods

addView

Added in API level 1
void addView (View child, 
                int index, 
                ViewGroup.LayoutParams params)

添加具有指定布局参数的子视图。

注意:不要调用此方法 draw(android.graphics.Canvas)onDraw(android.graphics.Canvas)dispatchDraw(android.graphics.Canvas)或任何相关方法。

Parameters
child View: the child view to add
index int: the position at which to add the child or -1 to add last
params ViewGroup.LayoutParams: the layout parameters to set on the child
Throws
IllegalStateException if this switcher already contains two children

getAccessibilityClassName

Added in API level 23
CharSequence getAccessibilityClassName ()

返回此对象的类名称以用于辅助功能。 如果子类正在实现的东西应该被视为一个全新的视图类,当它被可访问性使用时,子类只应该覆盖这个子类,与它所源自的类无关。 这用于填写AccessibilityNodeInfo.setClassName

Returns
CharSequence

getNextView

Added in API level 1
View getNextView ()

返回要显示的下一个视图。

Returns
View the view that will be displayed after the next views flip.

reset

Added in API level 1
void reset ()

重置ViewSwitcher以隐藏所有现有视图,并使其认为第一次动画尚未播放。

setFactory

Added in API level 1
void setFactory (ViewSwitcher.ViewFactory factory)

设置用于创建ViewSwitcher将翻转的两个视图的工厂。 不要使用工厂,您可以拨打addView(android.view.View, int, android.view.ViewGroup.LayoutParams)两次。

Parameters
factory ViewSwitcher.ViewFactory: the view factory used to generate the switcher's content

Hooray!