Code example for TranslateAnimation

Methods: setAnimationListener, setDuration, setFillAfter, setInterpolator

0
	private void animateActiveViewToAnchor() { 
		final DraggableView activeView = getActiveDraggableView();
		if (activeView.getXOffset() == activeView.getAnchorX()) return; 	
			 
		final float originalOffset = activeView.getXOffset() - activeView.getAnchorX();
		TranslateAnimation animation = new TranslateAnimation(0, 0, activeView.getTop(), activeView.getTop()){
			@Override 
			protected void applyTransformation(float interpolatedTime,
					Transformation t) {
				Log.i("AndroidHack", "Animating from: "+originalOffset+" to:"+activeView.getAnchorX());
				activeView.setXOffset(activeView.getAnchorX() + originalOffset - (interpolatedTime)*originalOffset);
			} 
		}; 
		AnimationListener listener = new AnimationListener() {
			 
			@Override 
			public void onAnimationStart(Animation animation) {
			} 
			 
			@Override 
			public void onAnimationRepeat(Animation animation) {
			} 
			 
			@Override 
			public void onAnimationEnd(Animation animation) {
				Log.i("AndroidHack", "Done animating");
				activeView.setAnimation(null);
			} 
		}; 
		animation.setDuration(500);
		animation.setInterpolator(new DecelerateInterpolator());
		animation.setAnimationListener(listener);
		animation.setFillAfter(true);
		activeView.startAnimation(animation);
	} 
 
 
	public DraggableView getActiveDraggableView() { 
		return (DraggableView) getChildAt(getChildCount() - 1);