Android Animation - 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 Animation class.

This code example shows how to use the following methods:setAnimationListener, setDuration, setFillBefore, setFillEnabled, setInterpolator
This code example shows how to use the following methods:setInterpolator, addAnimation, setDuration
    fadeOut=AnimationUtils.loadAnimation(ctxt, R.anim.fade);
  } 
   
  public void toggle() { 
    TranslateAnimation anim=null;
    AnimationSet set=new AnimationSet(true);
     
    isOpen=!isOpen;
     
    if (isOpen) {
      setVisibility(View.VISIBLE);
      anim=new TranslateAnimation(0.0f, 0.0f,
                                  getHeight(),
                                  0.0f); 
    } 
    else { 
      anim=new TranslateAnimation(0.0f, 0.0f, 0.0f,
                                  getHeight());
      anim.setAnimationListener(collapseListener);
      set.addAnimation(fadeOut);

9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDuration, setFillAfter, setFillEnabled, setInterpolator
			if(olddegree == 0 && newdegree == 270){
				newdegree = -90;
			} else if(olddegree == 270 && newdegree == 0){
				newdegree = 360;
			} 
			retval = new RotateAnimation(olddegree,
					newdegree,
					Animation.RELATIVE_TO_SELF,
					0.5f, 
					Animation.RELATIVE_TO_SELF,
					0.5f); 
 
			retval.setDuration(500);
			retval.setFillEnabled(true);
			retval.setFillAfter(true);
			retval.setInterpolator(new DecelerateInterpolator());
		} 
 
		return retval;
	} 
	 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setAnimationListener, setDuration, setInterpolator
      anim=new TranslateAnimation(0.0f, 0.0f,
                                  getHeight(),
                                  0.0f); 
    } 
    else { 
      anim=new TranslateAnimation(0.0f, 0.0f, 0.0f,
                                  getHeight());
      anim.setAnimationListener(collapseListener);
    } 
     
    anim.setDuration(speed);
    anim.setInterpolator(new AccelerateInterpolator(1.0f));
    startAnimation(anim);
  } 
   
  Animation.AnimationListener collapseListener=new Animation.AnimationListener() {
    public void onAnimationEnd(Animation animation) { 
      setVisibility(View.INVISIBLE); 
    } 
     
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setAnimationListener, setDuration, setFillAfter, setInterpolator, setStartOffset
    } 
 
    private static Animation createExpandAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta,
            long startOffset, long duration, Interpolator interpolator) {
        Animation animation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 0, 720);
        animation.setStartOffset(startOffset);
        animation.setDuration(duration);
        animation.setInterpolator(interpolator);
        animation.setFillAfter(true);
 
        return animation;
    } 
 
    private static Animation createShrinkAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta,
            long startOffset, long duration, Interpolator interpolator) {
        AnimationSet animationSet = new AnimationSet(false);
        animationSet.setFillAfter(true);
 
        final long preDuration = duration / 2;
        Animation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setFillEnabled, addAnimation, setFillAfter
        View v = getChildAt(dragged);
        int x = getCoorFromIndex(dragged).x + childWidth / 2, y = getCoorFromIndex(dragged).y
                + childWidth / 2;
        int l = x - (3 * childWidth / 4), t = y - (3 * childHeight / 4);
        v.layout(l, t, l + (childWidth * 3 / 2), t + (childHeight * 3 / 2));
        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(.667f, 1, .667f, 1,
                childWidth * 3 / 4, childHeight * 3 / 4);
        scale.setDuration(animT);
        AlphaAnimation alpha = new AlphaAnimation(1, .5f);
        alpha.setDuration(animT);
 
        animSet.addAnimation(scale);
        animSet.addAnimation(alpha);
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);
 
        v.clearAnimation();
        v.startAnimation(animSet);
    } 
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDuration, setRepeatCount, setRepeatMode
        final BitmapsView view = new BitmapsView(this);
        final FrameLayout layout = new FrameLayout(this);
        layout.addView(view, new FrameLayout.LayoutParams(480, 800, Gravity.CENTER));
        setContentView(layout);
         
        ScaleAnimation a = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f,
                ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
                ScaleAnimation.RELATIVE_TO_SELF,0.5f);
        a.setDuration(2000);
        a.setRepeatCount(Animation.INFINITE);
        a.setRepeatMode(Animation.REVERSE);
        view.startAnimation(a);
    } 
 
    static class BitmapsView extends View {
        private Paint mBitmapPaint;
        private final Bitmap mBitmap1;
        private final Bitmap mBitmap2;
        private final PorterDuffXfermode mDstIn;
 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setAnimationListener, setDuration
	            break; 
	        case BOTTOM:
	            y=getHeight();
	            break; 
		}		 
		TranslateAnimation anim=new TranslateAnimation(0, x, 0,y);
		anim.setDuration(ANIM_DURATION);
		anim.setAnimationListener(new AnimationListener() {
			 
			//@Override 
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub 
			} 
			 
			//@Override 
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub 
			} 
			 
			//@Override 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDuration, setFillAfter
			return null; 
		} 
 
		int dx = getLeft() - old_x;
		int dy = getTop() - old_y;
		Animation a = new TranslateAnimation(-dx, 0, -dy, 0);
		a.setFillAfter(true);
		a.setDuration(durationMillis);
 
		old_x = getLeft();
		old_y = getTop();
 
		return a;
	} 
 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setAnimationListener, setDuration, setFillBefore, setFillEnabled, setInterpolator
        TranslateAnimation anim;
        if (mExpanded) {
            anim = new TranslateAnimation(0, offset, 0, 0);
            mFillOffset = offset;
        } else { 
            anim = new TranslateAnimation(0, -offset, 0, 0);
            mFillOffset = -offset;
        } 
        mExpanded = !mExpanded;
        anim.setFillEnabled(true);
        anim.setFillBefore(true);
        anim.setDuration(300);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setAnimationListener(new AnimationFiller());
        content.startAnimation(anim);
    } 
     
    private class Toggler implements OnClickListener {
 
        @Override 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android Animation Questions & Answers:

Other Android Animation Examples

9:	// animation listeners
10:		@Override
11:		public void onAnimationEnd(Animation animation) {
12:			// Take any action after completing the animation
13:			// check for fade in animation
-
20:	
21:		@Override
22:		public void onAnimationRepeat(Animation animation) {
23:			// Animation is repeating
24:		}
-
25:	
26:		@Override
27:		public void onAnimationStart(Animation animation) {
28:			// Animation started
29:		}

Read More

1:	Animation animFadeIn, animFadeOut;
2:	.
3:	.

Read More

16:	
17:		// Animation
18:		Animation animFadein;
19:	
20:		@Override
-
49:	
50:		@Override
51:		public void onAnimationEnd(Animation animation) {
52:			// Take any action after completing the animation
53:	
-
61:	
62:		@Override
63:		public void onAnimationRepeat(Animation animation) {
64:			// TODO Auto-generated method stub
65:	
-
67:	
68:		@Override
69:		public void onAnimationStart(Animation animation) {
70:			// TODO Auto-generated method stub
71:

Read More

See Code Examples for Android Animation Methods: