动画小结

一、Tween动画
1、特点:
1.只是实现了简单的渐变,平移,拉伸,缩放;
2.Tween动画实现完成以后,该动画会恢复原状,自身属性并没有发生任何改变,动画的形成是通过父布局改变了其位置或渐变度,从而来改变其本身在短时间内的属性
3.此动画的形成是依赖于其父布局的,其属性没有发生任何改变
2、在Tween动画中所有动画的父类是Animation。
3、动画的渐变
/**
* 渐变
*/
private void alpin(){
/**
* 第一个参数:表示开始的透明度
* 第二个参数:表示结束的透明度
* 透明度的范围是0-1;1表示完全不透明;0表示完全透明
*/
Animation animation=new AlphaAnimation(0,1);
animation.setDuration(3000);
//设置动画重复的次数
animation.setRepeatCount(5);
/**
* Animation.REVERSE:重复的时候进行反转
* Animation.RESTART:每次执行都重新开始
*/
animation.setRepeatMode(Animation.RESTART);
animation.setAnimationListener(new Animation.AnimationListener() {
/**
* 动画开始执行的时候的一个回调
* @param animation
*/
@Override
public void onAnimationStart(Animation animation) {
}
/**
* 动画结束的时候的一个回调
* @param animation
*/
@Override
public void onAnimationEnd(Animation animation) {
}
/**
* 动画重复执行的时候的一个回调
* @param animation
*/
@Override
public void onAnimationRepeat(Animation animation) {
}
});
mImageView.startAnimation(animation);
}
4、动画的缩放
/**
* 缩放
*/
private void scale(){
//按照宽和高的倍数来进行缩放
//默认的缩放点是左上角
// Animation animation=new ScaleAnimation(0.5f,1,0.5f,1);
//后面的两个参数是像素,确定缩放点的坐标
// Animation animation=new ScaleAnimation(0,1,0,1,mImageView.getWidth()/2,mImageView.getHeight()/2);
//后面的四个参数是用来确定缩放点的坐标
Animation animation=new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);
animation.setRepeatCount(5);
animation.setRepeatMode(Animation.REVERSE);
mImageView.startAnimation(animation);
}
5、动画的平移
/**
*平移
*/
private void traslate(){
/**
* 坐标0,0是以自身左上角定点的坐标为坐标点;移动的单位是像素。
*/
// Animation animation=new TranslateAnimation(0,100,0,100);
/**
* 相对点的确定:
* Animation.RELATIVE_TO_SELF:相对于自己
* Animation.ABSOLUTE:相对于绝对点(很少用)
* Animation.RELATIVE_TO_PARENT:相对于父容器
*
* 值的确定:
* 是以当前宽和该乘以倍数后所确定的坐标
*/
Animation animation=new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,1f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,1f);
animation.setDuration(2000);
animation.setRepeatMode(Animation.REVERSE);
animation.setRepeatCount(5);
mImageView.startAnimation(animation);
}
6、动画的旋转
/**
* 旋转
*/
private void rotation(){
//默认的旋转点就是以左上角为旋转点
// Animation animation=new RotateAnimation(0,180);
//后面的两个参数表示的像素,确定的是旋转点的位置
// Animation animation=new RotateAnimation(0,180,mImageView.getWidth()/2,mImageView.getWidth()/2);
//后面的四个参数,都是为了确定的旋转点的位置,是按照宽和高的倍数来确定位置
Animation animation=new RotateAnimation(0,180,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);
animation.setRepeatCount(5);
animation.setRepeatMode(Animation.REVERSE);
mImageView.startAnimation(animation);
}
7、多动画同时执行
步骤:
1.获取一个AnimationSet对象;
2.定义一系列动画(一个或多个);
3.将定义的动画添加到动画集中;
4.设置动画的参数(时间,循环次数,循环方式);
5.使用View对象的startAnimation方法启动动画集;
/**
* 多动画同时执行
*/
private void manyAnima(){
Animation animation=new AlphaAnimation(0,1);
Animation animation1=new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
Animation animation2=new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
AnimationSet animationSet=new AnimationSet(true);
animationSet.addAnimation(animation);
animationSet.addAnimation(animation1);
animationSet.addAnimation(animation2);
animationSet.setDuration(5000);
mImageView.startAnimation(animationSet);
}
8、通过配置文件实现动画的步骤:
1.在res的目录下建立一个anim的文件夹;
2.在xml文件中配置相应的动画属性;
3.通过AnimationUtils的LoadAnimation()方法加载动画;
4.设置动画的相应属性;
5.运行动画。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员丶星霖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值