to top
Android APIs
public class

ViewAnimator

extends FrameLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.widget.ViewAnimator
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Base class for a FrameLayout container that will perform animations when switching between its views.

Summary

XML Attributes
Attribute Name Related Method Description
android:animateFirstView Defines whether to animate the current View when the ViewAnimation is first displayed. 
android:inAnimation Identifier for the animation to use when a view is shown. 
android:outAnimation Identifier for the animation to use when a view is hidden. 
[Expand]
Inherited XML Attributes
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
ViewAnimator(Context context)
ViewAnimator(Context context, AttributeSet attrs)
Public Methods
void addView(View child, int index, ViewGroup.LayoutParams params)
Adds a child view with the specified layout parameters.
int getBaseline()

Return the offset of the widget's text baseline from the widget's top boundary.

View getCurrentView()
Returns the View corresponding to the currently displayed child.
int getDisplayedChild()
Returns the index of the currently displayed child view.
Animation getInAnimation()
Returns the current animation used to animate a View that enters the screen.
Animation getOutAnimation()
Returns the current animation used to animate a View that exits the screen.
void onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
void removeAllViews()
Call this method to remove all child views from the ViewGroup.
void removeView(View view)

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

void removeViewAt(int index)
Removes the view at the specified position in the group.
void removeViewInLayout(View view)
Removes a view during layout.
void removeViews(int start, int count)
Removes the specified range of views from the group.
void removeViewsInLayout(int start, int count)
Removes a range of views during layout.
void setAnimateFirstView(boolean animate)
Indicates whether the current View should be animated the first time the ViewAnimation is displayed.
void setDisplayedChild(int whichChild)
Sets which child view will be displayed.
void setInAnimation(Context context, int resourceID)
Specifies the animation used to animate a View that enters the screen.
void setInAnimation(Animation inAnimation)
Specifies the animation used to animate a View that enters the screen.
void setOutAnimation(Animation outAnimation)
Specifies the animation used to animate a View that exit the screen.
void setOutAnimation(Context context, int resourceID)
Specifies the animation used to animate a View that exit the screen.
void showNext()
Manually shows the next child.
void showPrevious()
Manually shows the previous child.
[Expand]
Inherited Methods
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

XML Attributes

android:animateFirstView

Defines whether to animate the current View when the ViewAnimation is first displayed.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol animateFirstView.

Related Methods

android:inAnimation

Identifier for the animation to use when a view is shown.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol inAnimation.

Related Methods

android:outAnimation

Identifier for the animation to use when a view is hidden.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol outAnimation.

Related Methods

Public Constructors

public ViewAnimator (Context context)

Since: API Level 1

public ViewAnimator (Context context, AttributeSet attrs)

Since: API Level 1

Public Methods

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

Since: API Level 1

Adds a child view with the specified layout parameters.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
child the child view to add
index the position at which to add the child
params the layout parameters to set on the child

public int getBaseline ()

Since: API Level 1

Return the offset of the widget's text baseline from the widget's top boundary. If this widget does not support baseline alignment, this method returns -1.

Returns
  • the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

public View getCurrentView ()

Since: API Level 1

Returns the View corresponding to the currently displayed child.

Returns
  • The View currently displayed.

public int getDisplayedChild ()

Since: API Level 1

Returns the index of the currently displayed child view.

public Animation getInAnimation ()

Since: API Level 1

Returns the current animation used to animate a View that enters the screen.

Returns
  • An Animation or null if none is set.

public Animation getOutAnimation ()

Since: API Level 1

Returns the current animation used to animate a View that exits the screen.

Returns
  • An Animation or null if none is set.

public void onInitializeAccessibilityEvent (AccessibilityEvent event)

Since: API Level 14

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The event to initialize.

public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)

Since: API Level 14

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo) is responsible for handling this call.

Parameters
info The instance to initialize.

public void removeAllViews ()

Since: API Level 1

Call this method to remove all child views from the ViewGroup.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

public void removeView (View view)

Since: API Level 1

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

public void removeViewAt (int index)

Since: API Level 1

Removes the view at the specified position in the group.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
index the position in the group of the view to remove

public void removeViewInLayout (View view)

Since: API Level 1

Removes a view during layout. This is useful if in your onLayout() method, you need to remove more views.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
view the view to remove from the group

public void removeViews (int start, int count)

Since: API Level 1

Removes the specified range of views from the group.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
start the first position in the group of the range of views to remove
count the number of views to remove

public void removeViewsInLayout (int start, int count)

Since: API Level 1

Removes a range of views during layout. This is useful if in your onLayout() method, you need to remove more views.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
start the index of the first view to remove from the group
count the number of views to remove from the group

public void setAnimateFirstView (boolean animate)

Since: API Level 1

Indicates whether the current View should be animated the first time the ViewAnimation is displayed.

Parameters
animate True to animate the current View the first time it is displayed, false otherwise.

public void setDisplayedChild (int whichChild)

Since: API Level 1

Sets which child view will be displayed.

Parameters
whichChild the index of the child view to display

public void setInAnimation (Context context, int resourceID)

Since: API Level 1

Specifies the animation used to animate a View that enters the screen.

Parameters
context The application's environment.
resourceID The resource id of the animation.

public void setInAnimation (Animation inAnimation)

Since: API Level 1

Specifies the animation used to animate a View that enters the screen.

Parameters
inAnimation The animation started when a View enters the screen.

public void setOutAnimation (Animation outAnimation)

Since: API Level 1

Specifies the animation used to animate a View that exit the screen.

Parameters
outAnimation The animation started when a View exit the screen.

public void setOutAnimation (Context context, int resourceID)

Since: API Level 1

Specifies the animation used to animate a View that exit the screen.

Parameters
context The application's environment.
resourceID The resource id of the animation.

public void showNext ()

Since: API Level 1

Manually shows the next child.

public void showPrevious ()

Since: API Level 1

Manually shows the previous child.