AnimaitonManager.java 1.84 KB
package com.glsx.aicar.manager;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.OvershootInterpolator;
import android.view.animation.ScaleAnimation;

/**
 * 缩放动画管理类
 */
public class AnimaitonManager {
	private static AnimaitonManager instance;

/*	public synchronized static AnimaitonManager getInstance() {
		if (instance == null) {
			instance = new AnimaitonManager();
		}
		return instance;
	}*/

	//单例安全及性能优化
	private static class Holder{
		private static final AnimaitonManager INSTANCE = new AnimaitonManager();
	}

	public static final AnimaitonManager getInstance(){
		return Holder.INSTANCE;
	}

	public Animation getScaleOutAnimation() {
		ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		//动画持续时长
		scaleAnimation.setDuration(1000);
		//动画结束之后是否保持动画的最终状态
		scaleAnimation.setFillAfter(true);
		//动画插值器。是实现动画不规则运动的一种方式
		scaleAnimation.setInterpolator(new OvershootInterpolator());
		return scaleAnimation;
	}
	
	public Animation getAlphaOutAnimation() {
		AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f,1.0f);
		alphaAnimation.setDuration(500);
		alphaAnimation.setFillAfter(true);
		alphaAnimation.setInterpolator(new OvershootInterpolator());
		return alphaAnimation;
	}
	
	public Animation getScaleOutAnimation(long delay) {
		ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		scaleAnimation.setDuration(1000);
		scaleAnimation.setStartOffset(delay);
		scaleAnimation.setFillAfter(true);
		//scaleAnimation.setInterpolator(new OvershootInterpolator());
		return scaleAnimation;
	}
}