Android Animator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Animator class.

This code example shows how to use the following methods:addListener, playTogether, setDuration, start
        // Post this on the UI thread's message queue. It's needed for the items to be already measured 
        new Handler().post(new Runnable() {
 
            @Override 
            public void run() { 
                mSetAnim = new AnimatorSet();
                mTopImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                mBottomImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                mSetAnim.addListener(new Animator.AnimatorListener() {
                    @Override 
                    public void onAnimationStart(Animator animation) {
                    } 
 
                    @Override 
                    public void onAnimationEnd(Animator animation) {
                        clean(destActivity);
                    } 
 
                    @Override 
                    public void onAnimationCancel(Animator animation) {

7
CodeRank
This code example shows how to use the following methods:addListener, playTogether, setDuration, setInterpolator, start
This code example shows how to use the following methods:end, isRunning, setTarget, start
            container.start(view, closing);
        } 
    } 
 
    private void start(View view, boolean closing) {
        if (mEnterAnimation.isRunning()) {
            mEnterAnimation.end();
        } 
        if (mExitAnimation.isRunning()) {
            mExitAnimation.end();
        } 
        if (view.getVisibility() != View.VISIBLE) {
            if (!closing) {
                mEnterAnimation.setTarget(view);
                mEnterAnimation.start();
            } 
        } else if (closing) {
            mExitAnimation.setTarget(view);
            mExitAnimation.start();
        } else { 

7
CodeRank
This code example shows how to use the following methods:addListener, cancel
6
CodeRank
This code example shows how to use the following methods:addListener, play, start
        } else { 
            final long duration = getResources().getInteger(android.R.integer.config_shortAnimTime);
 
            // Animate if we have Honeycomb APIs, don't animate otherwise 
            mIsAnimating = true;
            AnimatorSet animatorSet = new AnimatorSet();
            mMasterView.setLayerType(LAYER_TYPE_HARDWARE, null);
            mDetailView.setLayerType(LAYER_TYPE_HARDWARE, null);
            animatorSet
                    .play(ObjectAnimator
                            .ofFloat(mMasterView, "translationX", translationX)
                            .setDuration(duration))
                    .with(ObjectAnimator
                            .ofFloat(mDetailView, "translationX", translationX)
                            .setDuration(duration));
            animatorSet.addListener(this);
            animatorSet.start();
 
            // For API level 12+, use this instead: 
            // mMasterView.animate().translationX().setDuration(duration); 

6
CodeRank
This code example shows how to use the following methods:addListener, start
6
CodeRank
This code example shows how to use the following methods:addListener, play, start
        } else { 
            final long duration = getResources().getInteger(android.R.integer.config_shortAnimTime);
 
            // Animate if we have Honeycomb APIs, don't animate otherwise 
            mIsAnimating = true;
            AnimatorSet animatorSet = new AnimatorSet();
            mMasterView.setLayerType(LAYER_TYPE_HARDWARE, null);
            mDetailView.setLayerType(LAYER_TYPE_HARDWARE, null);
            animatorSet
                    .play(ObjectAnimator
                            .ofFloat(mMasterView, "translationX", translationX)
                            .setDuration(duration))
                    .with(ObjectAnimator
                            .ofFloat(mDetailView, "translationX", translationX)
                            .setDuration(duration));
            animatorSet.addListener(this);
            animatorSet.start();
 
            // For API level 12+, use this instead: 
            // mMasterView.animate().translationX().setDuration(duration); 

6
CodeRank
This code example shows how to use the following methods:addListener, play, start
This code example shows how to use the following methods:addListener, end
6
CodeRank
This code example shows how to use the following methods:addListener, setDuration, start
            } 
 
            CrossFadeDrawable crossFadeDrawable = newCrossFadeDrawable(from, to);
            ObjectAnimator animator = crossFadeDrawable.getAnimator();
            imageView.setImageDrawable(crossFadeDrawable);
            animator.setDuration(ANIMATION_DURATION);
            animator.addListener(new AnimatorListenerAdapter() {
                @Override 
                public void onAnimationStart(Animator animation) {
                    if (FADE_DBG) {
                        log("cross-fade animation start (" 
                                + Integer.toHexString(from.hashCode()) + " -> "
                                + Integer.toHexString(to.hashCode()) + ")");
                    } 
                } 
 
                @Override 
                public void onAnimationEnd(Animator animation) {
                    if (FADE_DBG) {
                        log("cross-fade animation ended (" 

7
CodeRank
This code example shows how to use the following methods:addListener, addUpdateListener, setDuration, setInterpolator, start
            mAnimator.cancel();
        } 
        float from = mLeftToRight ? 0f : 1f;
        float to = mLeftToRight ? 1f : 0f;
        mAnimator = ValueAnimator.ofFloat(from, to);
        mAnimator.setDuration(DURATION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addListener(new AnimatorListenerAdapter() {
            @Override 
            public void onAnimationEnd(Animator animation) {
                mDrawDots = false;
                // make sure we draw one frame at the end with everything gone. 
                invalidate();
            } 
 
            @Override 
            public void onAnimationStart(Animator animation) {
                mDrawDots = true;
            } 
        }); 

7
CodeRank
This code example shows how to use the following methods:start
 
    @Override 
    public Result preAnimation() {
        // start the animation. This will send a message to the handler right away, so 
        // the queue is filled when this method returns. 
        mAnimator.start();
 
        return Status.SUCCESS.createResult(); 
    } 
 
    @Override 
    public void postAnimation() { 
        // nothing to be done. 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:addListener, play, setDuration
        mModestyPanel.setLayoutParams(layout);
        addView(mModestyPanel);
        mFadePanel = ObjectAnimator.ofFloat(mModestyPanel, "alpha", 0f);
        mFadeView = ObjectAnimator.ofFloat(null, "alpha", 0f);
        mAnimatorListener = new BringToFrontOnEnd();
        mTransitionAnimation = new AnimatorSet();
        mTransitionAnimation.play(mFadeView).with(mFadePanel);
        mTransitionAnimation.setDuration(CROSSFADE_TIME);
        mTransitionAnimation.addListener(mAnimatorListener);
    } 
 
    /** 
     * Visible for testing 
     * @hide 
     */ 
    public Animator getTransitionAnimation() {
        return mTransitionAnimation;
    } 
 
    /** 
6
CodeRank
This code example shows how to use the following methods:addListener, addUpdateListener, setDuration, start
This code example shows how to use the following methods:addListener, start, addUpdateListener, setInterpolator
        cancel(false); 
        animator = newInstance;
 
        // Invalidate 
        if (update == null) {
            animator.addUpdateListener(new AnimatorUpdateListener() {
                float oldValue = -1f;
 
                @Override 
                public void onAnimationUpdate(ValueAnimator animation) {
                    final float value = animation.getAnimatedFraction();
                    if (value != oldValue) rootView.postInvalidate();
                    oldValue = value;
                }}); 
        } else { 
            animator.addUpdateListener(update);
        } 
         
        animator.setInterpolator(interpolator);
 

7
CodeRank
This code example shows how to use the following methods:addListener, play, start
		@Override 
		public void setCardImage(final ImageButton ib, final int drawable) {
			ObjectAnimator animX = ObjectAnimator.ofFloat(ib, "scaleX", 1.f, 0.f);
			ObjectAnimator animY = ObjectAnimator.ofFloat(ib, "scaleY", 1.f, 0.f);
			animX.setDuration(500); animY.setDuration(500);
			final AnimatorSet scalers = new AnimatorSet();
			scalers.play(animX).with(animY);
			scalers.addListener(new AnimatorListenerAdapter() {
 
				@Override 
				public void onAnimationEnd(Animator animation) {
					ib.setScaleX(1.f);
					ib.setScaleY(1.f);
					ib.setImageResource(drawable);
				} 
 
			}); 
			scalers.start();
		} 
	} 

6
CodeRank
This code example shows how to use the following methods:end
        if (mVisibilityAnim != null) {
            mVisibilityAnim.end();
        } 
        super.setVisibility(visibility);
    } 
 
    public boolean showOverflowMenu() { 
        if (mActionMenuPresenter != null) {
            return mActionMenuPresenter.showOverflowMenu();
        } 
        return false; 
    } 
 
    public void postShowOverflowMenu() { 
        post(new Runnable() {
            public void run() { 
                showOverflowMenu(); 
            } 
        }); 
    } 
6
CodeRank
This code example shows how to use the following methods:addListener, play, start
        } else { 
            final long duration = getResources().getInteger(android.R.integer.config_shortAnimTime);
 
            // Animate if we have Honeycomb APIs, don't animate otherwise 
            mIsAnimating = true;
            AnimatorSet animatorSet = new AnimatorSet();
            mMasterView.setLayerType(LAYER_TYPE_HARDWARE, null);
            mDetailView.setLayerType(LAYER_TYPE_HARDWARE, null);
            animatorSet
                    .play(ObjectAnimator
                            .ofFloat(mMasterView, "translationX", translationX)
                            .setDuration(duration))
                    .with(ObjectAnimator
                            .ofFloat(mDetailView, "translationX", translationX)
                            .setDuration(duration));
            animatorSet.addListener(this);
            animatorSet.start();
 
            // For API level 12+, use this instead: 
            // mMasterView.animate().translationX().setDuration(duration); 

6
CodeRank
This code example shows how to use the following methods:cancel
        slideBanner(-mBannerHeight); // Slide up to hide.
    } 
 
    private void slideBanner(int toY) {
        if (mLastAnimator != null) {
            mLastAnimator.cancel();
        } 
 
        final PropertyValuesHolder[] values = {
                PropertyValuesHolder.ofInt(PROP_SET_BANNER_Y, getBannerY(), toY) };
        final ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
                this, values).setDuration(ANIMATION_DURATION);
        animator.setInterpolator(INTERPOLATOR);
        mLastAnimator = animator;
        animator.start();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:start
                    Animator anim = AnimatorInflater.loadAnimator(PropertyAnimations.this, animationID);
                    anim.setTarget(v);
                    anim.start();
                    return; 
                } 
                animation.start();
            } 
        }); 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:addListener, setDuration, start, setInterpolator
6
CodeRank
This code example shows how to use the following methods:setInterpolator, setInterpolator
 
                        s.play(shrink.setDuration(SLIDE_TIME/2)); 
                        s.play(grow.setDuration(SLIDE_TIME/2)).after(shrink); 
                        s.setInterpolator(mSlowStartWithBrakes); 
                    } else { 
                        AccelerateInterpolator accel = new AccelerateInterpolator(); 
                        DecelerateInterpolator decel = new DecelerateInterpolator(); 
 
                        shrink.setDuration(FADE_TIME).setInterpolator(accel); 
                        fadeout.setDuration(FADE_TIME).setInterpolator(accel); 
                        grow.setDuration(FADE_TIME).setInterpolator(decel); 
                        fadein.setDuration(FADE_TIME).setInterpolator(decel); 
                        s.play(shrink); 
                        s.play(fadeout); 
                        s.play(xMove.setDuration(0)).after(FADE_TIME); 
                        s.play(yMove.setDuration(0)).after(FADE_TIME); 
                        s.play(fadein).after(FADE_TIME); 
                        s.play(grow).after(FADE_TIME); 
                    } 
                    s.start(); 
5
CodeRank
This code example shows how to use the following methods:addListener, addUpdateListener, setDuration, setInterpolator, start
            mAnimator.cancel();
        } 
        float from = mLeftToRight ? 0f : 1f;
        float to = mLeftToRight ? 1f : 0f;
        mAnimator = ValueAnimator.ofFloat(from, to);
        mAnimator.setDuration(DURATION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addListener(new AnimatorListenerAdapter() {
            @Override 
            public void onAnimationEnd(Animator animation) {
                mDrawDots = false;
                // make sure we draw one frame at the end with everything gone. 
                invalidate();
            } 
 
            @Override 
            public void onAnimationStart(Animator animation) {
                mDrawDots = true;
            } 
        }); 

6
CodeRank
This code example shows how to use the following methods:addListener, setDuration, setInterpolator
        // callback below) 
        v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } 
 
    private void setupAnimation(ObjectAnimator anim, final View v) {
        anim.setInterpolator(sAccelerateInterpolator);
        anim.setDuration(sTransitionInDuration);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override 
            public void onAnimationEnd(Animator animation) {
                v.setLayerType(View.LAYER_TYPE_NONE, null);
            } 
        }); 
    } 
 
    @Override 
    protected void onFinishInflate() { 
        super.onFinishInflate(); 
 
        // Get the individual components 
6
CodeRank
This code example shows how to use the following methods:addListener, playTogether, setInterpolator, start
		ObjectAnimator animation6 = ObjectAnimator.ofFloat(mWeatherTxtHolder,
				"alpha", 0, 1); 
		animation6.setDuration(300);
		animation6.setStartDelay(300);
 
		AnimatorSet set = new AnimatorSet();
		set.playTogether(animation1, animation2, animation3, animation4,
				animation5,animation6);
		set.setInterpolator(new AccelerateDecelerateInterpolator());
		set.addListener(new AnimatorListener() {
 
			@Override 
			public void onAnimationStart(Animator animation) {
				// TODO Auto-generated method stub 
				animationLock = true;
			} 
 
			@Override 
			public void onAnimationRepeat(Animator animation) {
				// TODO Auto-generated method stub 

5
CodeRank
This code example shows how to use the following methods:addListener, play, start
            final long mDuration = getResources()
                    .getInteger(android.R.integer.config_shortAnimTime);
 
            /* Animate if we have Honeycomb APIs, don't animate otherwise */ 
            mIsAnimating = true;
            final AnimatorSet mAnimatorSet = new AnimatorSet();
            sMasterView.setLayerType(LAYER_TYPE_HARDWARE, null);
            mDetailView.setLayerType(LAYER_TYPE_HARDWARE, null);
            mAnimatorSet.play(
                    ObjectAnimator.ofFloat(sMasterView, "translationX", mTranslationX).setDuration(
                            mDuration)).with(
                    ObjectAnimator.ofFloat(mDetailView, "translationX", mTranslationX).setDuration(
                            mDuration));
            mAnimatorSet.addListener(this);
            mAnimatorSet.start();
        } 
    } 
 
    @Override 
    public void requestDisallowInterceptTouchEvent(final boolean disallowIntercept) {
6
CodeRank
This code example shows how to use the following methods:addListener, play, setDuration, setInterpolator, start
5
CodeRank
This code example shows how to use the following methods:addListener, setDuration, setInterpolator
        v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        v.buildLayer();
    } 
 
    private void setupAnimation(ObjectAnimator anim, final View v) {
        anim.setInterpolator(sAccelerateInterpolator);
        anim.setDuration(sTransitionInDuration);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override 
            public void onAnimationEnd(Animator animation) {
                v.setLayerType(View.LAYER_TYPE_NONE, null);
            } 
        }); 
    } 
 
    @Override 
    protected void onFinishInflate() { 
        super.onFinishInflate(); 
 
        // Get the individual components 
6
CodeRank
This code example shows how to use the following methods:addListener, setDuration, start, setInterpolator
            PropertyValuesHolder scaleUpY = PropertyValuesHolder.ofFloat("scaleY",
                    new float[] {currentScale, 1.0f});
            PropertyValuesHolder scaleUpAlpha = PropertyValuesHolder.ofFloat("alpha",
                    new float[] {currentAlpha, 1.0f});
            mScaleUpAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, scaleUpX, scaleUpY, scaleUpAlpha);
            mScaleUpAnimator.setInterpolator(new DecelerateInterpolator());
            mScaleUpAnimator.setDuration(SCALE_UP_DURATION_MS);
            mScaleUpAnimator.addListener(this);
            mScaleUpAnimator.start();
        } 
    } 
 
    public void dismiss() { 
        if (!mAttached) {
            return; 
        } 
        // Immediately set to false, to prevent .cancel() calls 
        // below from immediately calling into dismiss() again. 
        mAttached = false;
        mPreAnimator.cancel();
6
CodeRank
This code example shows how to use the following methods:addListener, playTogether, start
			mAniStart.setAlpha(.5f);
			mAniRepeat.setAlpha(.5f);
			mAniCancel.setAlpha(.5f);
			mAniEnd.setAlpha(.5f);
			 
			animatorSet.addListener(this);
			animatorSet.start();
		} 
		 
		public void createAnimation(){ 
			ObjectAnimator xAnim = ObjectAnimator.ofFloat(ball, "x", ball.getX(), 300);
			xAnim.setDuration(1000);
			xAnim.setInterpolator(new AccelerateInterpolator(2f));
			xAnim.addUpdateListener(this);
			 
			ObjectAnimator yAnim = ObjectAnimator.ofFloat(ball, "y", ball.getY(), getHeight() - 50f);
			yAnim.setDuration(1500);
			yAnim.setInterpolator(new AccelerateInterpolator(2f));
			yAnim.addUpdateListener(this);
			 

6
CodeRank

Related Android Animator Questions & Answers:

Other Android Animator Examples

33:	
34:	      @Override
35:	      public void onAnimationEnd(Animator animation) {
36:	        int nextX = randon.nextInt(width);
37:	        int nextY = randon.nextInt(height);

Read More

See Code Examples for Android Animator Methods: