android基本动画,代码构建动画 - 新闻资讯 - 云南小程序开发|云南软件开发|云南网站建设-昆明葵宇信息科技有限公司

159-8711-8523

云南网建设/小程序开发/软件开发

知识

不管是网站,软件还是小程序,都要直接或间接能为您产生价值,我们在追求其视觉表现的同时,更侧重于功能的便捷,营销的便利,运营的高效,让网站成为营销工具,让软件能切实提升企业内部管理水平和效率。优秀的程序为后期升级提供便捷的支持!

您当前位置>首页 » 新闻资讯 » 技术分享 >

android基本动画,代码构建动画

发表时间:2020-10-19

发布人:葵宇科技

浏览次数:41


应用代码构建android根本动画,根本动画有以下:
AlphaAnimation:渐变透明度动画
RotateAnimation:扭迁移转变画

ScaleAnimation:伸缩动画

TranslateAnimation:平移动画


可以定义出一些常用的动画效不雅,也可以自定义一些动画,把参数预留出来。
可以定义一些组合动画效不雅,例如:大年夜里到外的效不雅。对于组合的动画效不雅,应用根本的动画效不雅构建起来。
应用AnimationSet添加到此集合中,让其琅绫擎的动画一路起效不雅,可以看到意想不到的效不雅。
代码对象类
/**
 * 应用代码设计的动画
 * 
 */
public class AnimationCodeUtils {
	private static Animation anim;

	/**
	 * 默认的是: 1.透明度大年夜1.0~0, 2.动画时光3000毫秒 3.一向在动画停止状况
	 * 
	 * @return 渐变透明度动画
	 */
	public static AlphaAnimation alphaAnimation1To0() {
		AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
		alpha.setDuration(3000);
		return alpha;
	}

	/**
	 * 默认的是: 1.透明度大年夜0.0~1, 2.动画时光3000毫秒 3.一向在动画停止状况
	 * 
	 * @return 渐变透明度动画
	 */
	public static AlphaAnimation alphaAnimation0To1() {
		AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);
		alpha.setDuration(3000);
		return alpha;
	}

	/**
	 * @param fromAlpha
	 *            开端透明度(0~1.0)
	 * @param toAlpha
	 *            停止透明度(0~1.0)
	 * @param durationMillis
	 *            动画履行时光
	 * @param fillAfter
	 *            是否逗留在动画停止状况
	 * @return
	 */
	public static AlphaAnimation alphaAnimationCustom(float fromAlpha,
			float toAlpha, long durationMillis, boolean fillAfter) {
		AlphaAnimation alpha = new AlphaAnimation(fromAlpha, toAlpha);
		alpha.setDuration(durationMillis);
		alpha.setFillAfter(fillAfter);
		return alpha;
	}

	/**
	 * 扭迁移转变画,顺时针360 默认:1.扭转角度:0~360 2.相对于本身的中间肠位 3.扭转时光为30004.一向留在动画停止状况
	 * 
	 * @return
	 */
	public static RotateAnimation rotateAnimation0to360() {
		RotateAnimation rotate = new RotateAnimation(0f, 360f,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f);
		rotate.setDuration(3000);
		rotate.setFillAfter(false);
		return rotate;
	}

	/**
	 * 扭迁移转变画,逆时针360 默认:1.扭转角度:360-0 2.相对于本身的中间肠位 3.扭转时光为30004.一向留在动画停止状况
	 * 
	 * @return
	 */
	public static RotateAnimation rotateAnimation360to0() {
		RotateAnimation rotate = new RotateAnimation(360f, 0f,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f,
				RotateAnimation.RELATIVE_TO_SELF, 0.5f);
		rotate.setDuration(3000);
		rotate.setFillAfter(false);
		return rotate;
	}

	/**
	 * 
	 * 扭迁移转变画,自定义
	 * 
	 * @return
	 */
	/**
	 * @param fromDegrees
	 *            开端扭转的角度
	 * @param toDegrees
	 *            停止的角度
	 * @param pivotXType
	 *            X偏向相对地位类型
	 * @param pivotXValue
	 *            X偏向相对地位的值
	 * @param pivotYType
	 *            Y偏向相对地位类型
	 * @param pivotYValue
	 *            Y偏向相对地位的值
	 * @param durationMillis
	 *            动画履行时光
	 * @param fillAfter
	 *            是否逗留在动画停止时光
	 * @return
	 */
	public static RotateAnimation rotateAnimationCustom(float fromDegrees,
			float toDegrees, int pivotXType, float pivotXValue, int pivotYType,
			float pivotYValue, long durationMillis, boolean fillAfter) {
		RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees,
				pivotXType, pivotXValue, pivotYType, pivotYValue);
		rotate.setDuration(durationMillis);
		rotate.setFillAfter(fillAfter);
		return rotate;
	}

	/**
	 * 伸缩动画 默认:相对于本身,向左上角缩小,大年夜有到无,动画时光3000,一向留在动画停止状况
	 */
	public static ScaleAnimation scaleAnimation1to0() {
		ScaleAnimation scale = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f,
				ScaleAnimation.RELATIVE_TO_SELF, 0f,
				ScaleAnimation.RELATIVE_TO_SELF, 0f);
		scale.setDuration(3000);
		scale.setFillAfter(false);
		return scale;
	}

	/**
	 * 伸缩动画 默认:相对于本身,向左上角放大年夜,大年夜无到有,动画时光3000,一向留在动画停止状况
	 */
	public static ScaleAnimation scaleAnimation0to1() {
		ScaleAnimation scale = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
				ScaleAnimation.RELATIVE_TO_SELF, 0f,
				ScaleAnimation.RELATIVE_TO_SELF, 0f);
		scale.setDuration(3000);
		scale.setFillAfter(false);
		return scale;
	}

	/**
	 * 伸缩动画
	 */
	/**
	 * @param fromX
	 *            X偏向开端缩放的角度(0-1) 0是不显示,1是全部显示
	 * @param toX
	 *            X偏向停止缩放的角度(0-1) 0是不显示,1是全部显示
	 * @param fromY
	 *            Y偏向开端缩放的角度(0-1) 0是不显示,1是全部显示
	 * @param toY
	 *            Y偏向停止缩放的角度(0-1) 0是不显示,1是全部显示
	 * @param pivotXType
	 *            X偏向相对类型
	 * @param pivotXValue
	 *            X偏向相对于的值
	 * @param pivotYType
	 *            Y偏向相对类型
	 * @param pivotYValue
	 *            Y偏向相对于的值
	 * @param durationMillis
	 *            动画履行时光
	 * @param fillAfter
	 *            是否逗留在动画停止的状况
	 * @return
	 */
	public static ScaleAnimation scaleAnimationCustom(float fromX, float toX,
			float fromY, float toY, int pivotXType, float pivotXValue,
			int pivotYType, float pivotYValue, long durationMillis,
			boolean fillAfter) {
		ScaleAnimation scale = new ScaleAnimation(fromX, toX, fromY, toY,
				pivotXType, pivotXValue, pivotYType, pivotYValue);
		scale.setDuration(durationMillis);
		scale.setFillAfter(fillAfter);
		return scale;
	}

	/**
	 * 平移动画:大年夜左向右 平移
	 * 
	 * @return
	 */
	public static TranslateAnimation translateAnimationLeftToRight() {
		TranslateAnimation translate = new TranslateAnimation(
				TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
				TranslateAnimation.RELATIVE_TO_SELF, 1.0f,
				TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
				TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
		translate.setDuration(3000);
		translate.setFillAfter(false);
		return translate;
	}

	/**
	 * 平移动画:大年夜右向左 平移
	 * 
	 * @return
	 */
	public static TranslateAnimation translateAnimationRightToLeft() {
		TranslateAnimation translate = new TranslateAnimation(
				TranslateAnimation.RELATIVE_TO_SELF, 1.0f,
				TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
				TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
				TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
		translate.setDuration(3000);
		translate.setFillAfter(false);
		return translate;
	}

	/**
	 * 平移动画:自定义
	 * 
	 * @return
	 */
	/**
	 * @param fromXType
	 *            X偏向开端平移相对类型
	 * @param fromXValue
	 *            X偏向开端平移相对值
	 * @param toXType
	 *            X偏向停止平移相对类型
	 * @param toXValue
	 *            X偏向停止平移相对值
	 * @param fromYType
	 *            Y偏向开端平移相对类型
	 * @param fromYValue
	 *            Y偏向开端平移相对值
	 * @param toYType
	 *            Y偏向停止平移相对类型
	 * @param toYValue
	 *            Y偏向停止平移相对值
	 * @param durationMillis
	 *            动画履行时光
	 * @param fillAfter
	 *            是否逗留在动画停止状况
	 * @return
	 */
	public static TranslateAnimation translateAnimationCustom(int fromXType,
			float fromXValue, int toXType, float toXValue, int fromYType,
			float fromYValue, int toYType, float toYValue, long durationMillis,
			boolean fillAfter) {
		TranslateAnimation translate = new TranslateAnimation(fromXType,
				fromXValue, toXType, toXValue, fromYType, fromYValue, toYType,
				toYValue);
		translate.setDuration(durationMillis);
		translate.setFillAfter(fillAfter);
		return translate;
	}

	/**
	 * 动画集合:渐变-缩放-扭转;效不雅,大年夜里向外扭转放大年夜
	 * 
	 * @return
	 */
	public static Animation animationSet() {
		AnimationSet aniset = new AnimationSet(true);// true表示一路起感化
		aniset.addAnimation(alphaAnimation0To1());
		aniset.addAnimation(AnimationCodeUtils.scaleAnimationCustom(0f, 1f, 0f,
				1f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
				ScaleAnimation.RELATIVE_TO_SELF, 0.5f, 3000, false));
		aniset.addAnimation(rotateAnimation0to360());
		return aniset;
	}
}



源码下载:http://download.csdn.net/detail/forwardyzk/8317823
动画效不雅图:
[img]http://img.blog.csdn.net/20150104101740023?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm9yd2FyZHl6aw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

相关案例查看更多