FileDocCategorySizeDatePackage
ViewAnimator.javaAPI DocAndroid 1.5 API9323Wed May 06 22:41:56 BST 2009android.widget

ViewAnimator

public class ViewAnimator extends FrameLayout
Base class for a {@link FrameLayout} container that will perform animations when switching between its views.
attr
ref android.R.styleable#ViewAnimator_inAnimation
attr
ref android.R.styleable#ViewAnimator_outAnimation

Fields Summary
int
mWhichChild
boolean
mFirstTime
boolean
mAnimateFirstTime
android.view.animation.Animation
mInAnimation
android.view.animation.Animation
mOutAnimation
Constructors Summary
public ViewAnimator(android.content.Context context)


       
        super(context);
        initViewAnimator();
    
public ViewAnimator(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);

        TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ViewAnimator);
        int resource = a.getResourceId(com.android.internal.R.styleable.ViewAnimator_inAnimation, 0);
        if (resource > 0) {
            setInAnimation(context, resource);
        }

        resource = a.getResourceId(com.android.internal.R.styleable.ViewAnimator_outAnimation, 0);
        if (resource > 0) {
            setOutAnimation(context, resource);
        }
        a.recycle();

        initViewAnimator();
    
Methods Summary
public voidaddView(android.view.View child, int index, ViewGroup.LayoutParams params)

        super.addView(child, index, params);
        if (getChildCount() == 1) {
            child.setVisibility(View.VISIBLE);
        } else {
            child.setVisibility(View.GONE);
        }
    
public intgetBaseline()

        return (getCurrentView() != null) ? getCurrentView().getBaseline() : super.getBaseline();
    
public android.view.ViewgetCurrentView()
Returns the View corresponding to the currently displayed child.

return
The View currently displayed.
see
#getDisplayedChild()

        return getChildAt(mWhichChild);
    
public intgetDisplayedChild()
Returns the index of the currently displayed child view.

        return mWhichChild;
    
public android.view.animation.AnimationgetInAnimation()
Returns the current animation used to animate a View that enters the screen.

return
An Animation or null if none is set.
see
#setInAnimation(android.view.animation.Animation)
see
#setInAnimation(android.content.Context, int)

        return mInAnimation;
    
public android.view.animation.AnimationgetOutAnimation()
Returns the current animation used to animate a View that exits the screen.

return
An Animation or null if none is set.
see
#setOutAnimation(android.view.animation.Animation)
see
#setOutAnimation(android.content.Context, int)

        return mOutAnimation;
    
private voidinitViewAnimator()

        mMeasureAllChildren = true;
    
public voidremoveAllViews()

        super.removeAllViews();
        mWhichChild = 0;
        mFirstTime = true;
    
public voidremoveView(android.view.View view)

        final int index = indexOfChild(view);
        if (index >= 0) {
            removeViewAt(index);
        }
    
public voidremoveViewAt(int index)

        super.removeViewAt(index);
        final int childCount = getChildCount();
        if (childCount == 0) {
            mWhichChild = 0;
            mFirstTime = true;
        } else if (mWhichChild >= childCount) {
            // Displayed is above child count, so float down to top of stack
            setDisplayedChild(childCount - 1);
        } else if (mWhichChild == index) {
            // Displayed was removed, so show the new child living in its place
            setDisplayedChild(mWhichChild);
        }
    
public voidremoveViewInLayout(android.view.View view)

        removeView(view);
    
public voidremoveViews(int start, int count)

        super.removeViews(start, count);
        if (getChildCount() == 0) {
            mWhichChild = 0;
            mFirstTime = true;
        } else if (mWhichChild >= start && mWhichChild < start + count) {
            // Try showing new displayed child, wrapping if needed
            setDisplayedChild(mWhichChild);
        }
    
public voidremoveViewsInLayout(int start, int count)

        removeViews(start, count);
    
public voidsetAnimateFirstView(boolean animate)
Indicates whether the current View should be animated the first time the ViewAnimation is displayed.

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

        mAnimateFirstTime = animate;
    
public voidsetDisplayedChild(int whichChild)
Sets which child view will be displayed.

param
whichChild the index of the child view to display

        mWhichChild = whichChild;
        if (whichChild >= getChildCount()) {
            mWhichChild = 0;
        } else if (whichChild < 0) {
            mWhichChild = getChildCount() - 1;
        }
        boolean hasFocus = getFocusedChild() != null;
        // This will clear old focus if we had it
        showOnly(mWhichChild);
        if (hasFocus) {
            // Try to retake focus if we had it
            requestFocus(FOCUS_FORWARD);
        }
    
public voidsetInAnimation(android.view.animation.Animation inAnimation)
Specifies the animation used to animate a View that enters the screen.

param
inAnimation The animation started when a View enters the screen.
see
#getInAnimation()
see
#setInAnimation(android.content.Context, int)

        mInAnimation = inAnimation;
    
public voidsetInAnimation(android.content.Context context, int resourceID)
Specifies the animation used to animate a View that enters the screen.

param
context The application's environment.
param
resourceID The resource id of the animation.
see
#getInAnimation()
see
#setInAnimation(android.view.animation.Animation)

        setInAnimation(AnimationUtils.loadAnimation(context, resourceID));
    
public voidsetOutAnimation(android.view.animation.Animation outAnimation)
Specifies the animation used to animate a View that exit the screen.

param
outAnimation The animation started when a View exit the screen.
see
#getOutAnimation()
see
#setOutAnimation(android.content.Context, int)

        mOutAnimation = outAnimation;
    
public voidsetOutAnimation(android.content.Context context, int resourceID)
Specifies the animation used to animate a View that exit the screen.

param
context The application's environment.
param
resourceID The resource id of the animation.
see
#getOutAnimation()
see
#setOutAnimation(android.view.animation.Animation)

        setOutAnimation(AnimationUtils.loadAnimation(context, resourceID));
    
public voidshowNext()
Manually shows the next child.

        setDisplayedChild(mWhichChild + 1);
    
voidshowOnly(int childIndex)
Shows only the specified child. The other displays Views exit the screen with the {@link #getOutAnimation() out animation} and the specified child enters the screen with the {@link #getInAnimation() in animation}.

param
childIndex The index of the child to be shown.

        final int count = getChildCount();
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (i == childIndex) {
                if ((!mFirstTime || mAnimateFirstTime) && mInAnimation != null) {
                    child.startAnimation(mInAnimation);
                }
                child.setVisibility(View.VISIBLE);
                mFirstTime = false;
            } else {
                if (mOutAnimation != null && child.getVisibility() == View.VISIBLE) {
                    child.startAnimation(mOutAnimation);
                } else if (child.getAnimation() == mInAnimation)
                    child.clearAnimation();
                child.setVisibility(View.GONE);
            }
        }
    
public voidshowPrevious()
Manually shows the previous child.

        setDisplayedChild(mWhichChild - 1);