Android动画学习总结

记录学习动画的一些知识点。

View动画

view动画是android的基本动画,不改变动画的属性,相当于通过镜像去实现动画,view的点击位置不会发生改变,即时view的位置发生改变

view动画的分类

view动画可以分为4大类,平移动画(TranslateAnimation)、旋转动画(RotateAnimation)、透明动画(AlphaAnimation)、缩放动画(ScaleAnimation)

平移动画(TranslateAnimation)

  //第一个参数fromXDelta为动画起始时 X坐标上的移动位置
    //第二个参数toXDelta为动画结束时 X坐标上的移动位置
    //第三个参数fromYDelta为动画起始时Y坐标上的移动位置
    //第四个参数toYDelta为动画结束时Y坐标上的移动位置
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    TranslateAnimation translateAnimation = new TranslateAnimation(0, metrics.widthPixels / 2, 0, metrics.heightPixels / 2);
    translateAnimation.setDuration(2000);
    // 设置图形是否停留在结束位置
    translateAnimation.setFillAfter(true);
    //设置重复次数
    translateAnimation.setRepeatCount(2);
    //设置重复模式  Animation.REVERSE 在动画结束的位置重新反向执行动画  Animation.RESTART 在动画开始的位置重复执行动画
    translateAnimation.setRepeatMode( Animation.REVERSE);
    mView.startAnimation(translateAnimation);

旋转动画(RotateAnimation)

RotateAnimation animation = new RotateAnimaton(0,360,
Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f)
animation.setDuration(2000);
mView2.startAnimation(animation);
//Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f
这四个参数代表旋转的中心点事view的自身的中心点
Animation.RELATIVE_TO_SELF 是针对自身
Animation.RELATIVE_TO_PARENT 是针对父控件

透明动画(AlphaAnimation)

    AlphaAnimation animation = new AlphaAnimation(1.0f,0f);
    animation.setDuration(2000);
    animation.setInterpolator(new LinearInterpolator());
    mView.startAnimation(animation);
    表示是从不透明到全透明

缩放动画(ScaleAnimation)

    ScaleAnimation animation = new ScaleAnimation(1.0f,1.5f,1.0f,1.5f,Animation.RELATIVE_TO_SELF,1f,Animation.RELATIVE_TO_SELF,1f);
    animation.setDuration(2000);
    //动画的重复次数
    animation.setRepeatCount(1);
    mView.startAnimation(animation);
    后面四个参数决定缩放的中心点在View的中心

组合动画(AnimationSet)

组合动画是组合上面四种动画进行同时开始动画
     AnimationSet set = new AnimationSet(true);
    TranslateAnimation animation1 = new TranslateAnimation(0,100,0,100);
    animation1.setRepeatCount(1);
    animation1.setRepeatMode(Animation.REVERSE);
    AlphaAnimation animation2 = new AlphaAnimation(1.0f,0f);
    animation1.setRepeatCount(1);
    animation1.setRepeatMode(Animation.REVERSE);
    ScaleAnimation animation3 = new ScaleAnimation(1.0f,1.5f,1.0f,1.5f,Animation.RELATIVE_TO_SELF,1f,Animation.RELATIVE_TO_SELF,1f);
    animation1.setRepeatCount(1);
    animation1.setRepeatMode(Animation.REVERSE);
    set.addAnimation(animation1);
    set.addAnimation(animation2);
    set.addAnimation(animation3);
    set.setDuration(2000);
    mView.startAnimation(set);
    设置重复模式和重复次数只能在每一个动画中单独设置
    设置持续时间必须在AnimationSet中设置

View动画的总结

 view动画可以做一些简单的不改变控件属性(例如控件的颜色,坐标)的前提下去提高Ui的交互效果,比如可以做一些简单的Activity转场动画

property属性动画

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值