Android中View动画的学习掌握(补间动画,属性动画)

无论是补间动画还是属性动画都有俩种实现方法:

  1. 用代码定义
  2. 使用xml方式定义

补间动画

setDuration:设置动画时长
setRepeatCount:设置重复的次数
setRepeatMode:设置动画执行的模式
startAnimation:执行动画

1.实现透明效果[AlphaAnimation]

AlphaAnimation a1 = new AlphaAnimation(1.0f, 0.0f);
			a1.setDuration(2000);
			a1.setRepeatCount(1);
			a1.setRepeatMode(Animation.REVERSE);
			iv.startAnimation(a1);

2.实现旋转效果[RotateAnimation]

fromDegrees:开始的角度
toDegrees:结束的角度
Animation.RELATIVE_TO_SELF:以自身为中心旋转
	RotateAnimation a2 = new RotateAnimation(0, 360,
					Animation.RELATIVE_TO_SELF, 0.5f,
					Animation.RELATIVE_TO_SELF, 0.5f);
		 
			a2.setDuration(2000);
			a2.setRepeatCount(1);
			a2.setRepeatMode(Animation.REVERSE);
			iv.startAnimation(a2);


3.实现缩放效果[ScaleAnimation]

Animation.RELATIVE_TO_SELF:以自身为中心缩放
ScaleAnimation a3 = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f,
					Animation.RELATIVE_TO_SELF, 0.5f,
					Animation.RELATIVE_TO_SELF, 0.5f);
			a3.setDuration(2000);
			a3.setRepeatCount(1);
			a3.setRepeatMode(Animation.REVERSE);
			iv.startAnimation(a3);


2.实现位移效果[ Translate Animation]

setFillAfter:设置此属性为true意为动画停留在结束位置
Animation.RELATIVE_TO_PARENT:相对于父控件动
TranslateAnimation a4 = new TranslateAnimation(
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, 0.1f,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, 0);
			a4.setDuration(2000);
			// a4.setRepeatCount(1);
			a4.setRepeatMode(Animation.REVERSE);
			a4.setFillAfter(true);// 当前动画结束后,动画停留在结束位置
			iv.startAnimation(a4);


使用xml方式定义补间动画

(补间动画)

  1. android——res——建一个anim目录——new一个xml

  2. xml中设置的属性与在java中写的类似

  3. 在Activity中加载声明动画(AnimationUtils.loadAnimation(getApplicationContext(),R.anim.alpha));

(属性动画)
android——res——animator目录

属性动画【ObjectAnimation.ofFloat】

translationX:位移

scaleY:缩放

alpha:透明

rotationX:旋转

把动画集合实现

补间动画是(AnimationSet set=new AnimationSet)
属性动画是(AnimatorSet set=new AnimatorSet)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值