ViewAnimator

public class ViewAnimator
extends FrameLayout

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.widget.ViewAnimator


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

Inherited constants

Inherited fields

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 View.draw(android.graphics.Canvas), View.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

XML attributes

android:animateFirstView

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

May be a boolean value, such as "true" or "false".

android:inAnimation

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

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

android:outAnimation

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

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

Public constructors

ViewAnimator

Added in API level 1
public ViewAnimator (Context context)

Parameters
context Context

ViewAnimator

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

Parameters
context Context

attrs AttributeSet

Public methods

addView

Added in API level 1
public 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 View.draw(android.graphics.Canvas), View.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
public 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
public 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.

getBaseline

Added in API level 1
public 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
public View getCurrentView ()

Returns the View corresponding to the currently displayed child.

Returns
View The View currently displayed.

getDisplayedChild

Added in API level 1
public int getDisplayedChild ()

Returns the index of the currently displayed child view.

Returns
int

getInAnimation

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

getOutAnimation

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

removeAllViews

Added in API level 1
public void removeAllViews ()

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

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

removeView

Added in API level 1
public void removeView (View view)

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

Parameters
view View

removeViewAt

Added in API level 1
public void removeViewAt (int index)

Removes the view at the specified position in the group.

Note: do not invoke this method from View.draw(android.graphics.Canvas), View.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
public 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 View.draw(android.graphics.Canvas), View.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
public void removeViews (int start, 
                int count)

Removes the specified range of views from the group.

Note: do not invoke this method from View.draw(android.graphics.Canvas), View.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
public 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 View.draw(android.graphics.Canvas), View.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
public 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
public 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
public 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.

setInAnimation

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

setOutAnimation

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

setOutAnimation

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

showNext

Added in API level 1
public void showNext ()

Manually shows the next child.

showPrevious

Added in API level 1
public void showPrevious ()

Manually shows the previous child.