Most visited

Recently visited

Added in API level 1

ViewAnimator

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


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

Summary

XML attributes

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. 

Inherited XML attributes

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

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.

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

boolean getAnimateFirstView()

Returns whether the current View should be animated the first time the ViewAnimator is displayed.

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 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 ViewAnimator 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.

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.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

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.

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.

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.

Public constructors

ViewAnimator

Added in API level 1
ViewAnimator (Context context)

Parameters
context Context

ViewAnimator

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

Parameters
context Context
attrs AttributeSet

Public methods

addView

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

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 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

getAccessibilityClassName

Added in API level 23
CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getAnimateFirstView

Added in API level 17
boolean getAnimateFirstView ()

Returns whether the current View should be animated the first time the ViewAnimator is displayed.

Returns
boolean true if the current View will be animated the first time it is displayed, false otherwise.

See also:

getBaseline

Added in API level 1
int getBaseline ()

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
int the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

getCurrentView

Added in API level 1
View getCurrentView ()

Returns the View corresponding to the currently displayed child.

Returns
View The View currently displayed.

See also:

getDisplayedChild

Added in API level 1
int getDisplayedChild ()

Returns the index of the currently displayed child view.

Returns
int

getInAnimation

Added in API level 1
Animation getInAnimation ()

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

Returns
Animation An Animation or null if none is set.

See also:

getOutAnimation

Added in API level 1
Animation getOutAnimation ()

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

Returns
Animation An Animation or null if none is set.

See also:

removeAllViews

Added in API level 1
void removeAllViews ()

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.

removeView

Added in API level 1
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.

Parameters
view View

removeViewAt

Added in API level 1
void removeViewAt (int index)

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 int: the position in the group of the view to remove

removeViewInLayout

Added in API level 1
void removeViewInLayout (View view)

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 View: the view to remove from the group

removeViews

Added in API level 1
void removeViews (int start, 
                int count)

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 int: the first position in the group of the range of views to remove
count int: the number of views to remove

removeViewsInLayout

Added in API level 1
void removeViewsInLayout (int start, 
                int count)

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 int: the index of the first view to remove from the group
count int: the number of views to remove from the group

setAnimateFirstView

Added in API level 1
void setAnimateFirstView (boolean animate)

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

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

setDisplayedChild

Added in API level 1
void setDisplayedChild (int whichChild)

Sets which child view will be displayed.

Parameters
whichChild int: the index of the child view to display

setInAnimation

Added in API level 1
void setInAnimation (Context context, 
                int resourceID)

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

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

See also:

setInAnimation

Added in API level 1
void setInAnimation (Animation inAnimation)

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

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

See also:

setOutAnimation

Added in API level 1
void setOutAnimation (Animation outAnimation)

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

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

See also:

setOutAnimation

Added in API level 1
void setOutAnimation (Context context, 
                int resourceID)

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

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

See also:

showNext

Added in API level 1
void showNext ()

Manually shows the next child.

showPrevious

Added in API level 1
void showPrevious ()

Manually shows the previous child.

Hooray!