Code example for AnimationSet

Methods: addAnimation, setFillAfter, setFillEnabled, setInterpolator

0
		north = new ImageButton(m_Context);
		// this.setAlpha(0); 
	} 
 
	public void reset() { 
		AnimationSet animSet = new AnimationSet(true);
		animSet.setInterpolator(new DecelerateInterpolator());
		animSet.setFillAfter(true);
		animSet.setFillEnabled(true);
 
		final RotateAnimation animRotate = new RotateAnimation(-map_angle, 0,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f);
 
		animRotate.setDuration(600);
		animRotate.setFillAfter(true);
 
		animRotate.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 
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub 
 
				new Handler().postDelayed(new Runnable() {
					@Override 
					public void run() { 
 
						/** 
						 * Make the compass invisible if the animation is over 
						 * and map angle is still set to 0 
						 */ 
						if (map_angle == 0.0) {
							clearAnimation();
							setVisibility(View.INVISIBLE);
							postInvalidate();
 
						} 
					} 
				}, 700); 
 
			} 
		}); 
 
		animSet.addAnimation(animRotate);
 
		this.startAnimation(animSet);
		map_angle = 0;
 
	}