补件动画 / 属性动画

补间动画:动画开始到结尾的中间过程都是假象,渲染出来的,只是显示的位置变化了,View的实际位置还在原地,点击事件都在初试位置.
透明度动画(AlphaAnimation) 缩放动画(ScaleAnimation),平移动画(TranslateAnimation)旋转动画(RotateAnimation)

更多具体内容转载自一下连接:
版权声明:本文为CSDN博主「路很长oO」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_37667770/article/details/80007225

属性动画:

/**
     * 属性动画
     * 移动:translationX ,translationY
     * 旋转: rotation
     * 缩放: scaleX , scaleY
     * 渐变: alpha
     * */
     
     //渐变
 ObjectAnimator animator =ObjectAnimator.ofFloat(number_sign,"alpha",1.0f,0.8f,0.6f,0.4f,0.2f,0.4f,0.6f,0.8f,1f);
    animator.setDuration(2000);
    animator.setRepeatCount(-1);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.start();
	//缩放
    AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画
    ObjectAnimator scaleX = ObjectAnimator.ofFloat(number_sign, "scaleX", 0, 1f);
    ObjectAnimator scaleY = ObjectAnimator.ofFloat(number_sign, "scaleY", 0, 1f);
    animatorSetsuofang.setDuration(2000);
    animatorSetsuofang.setInterpolator(new DecelerateInterpolator());
    animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始
    animatorSetsuofang.start();
    //移动
ObjectAnimator translationX  =ObjectAnimator.ofFloat(number_sign,"translationX",0,0);
    ObjectAnimator translationY =ObjectAnimator.ofFloat(number_sign,"translationY",0,600f);
    AnimatorSet set =new AnimatorSet();
    set.playTogether(translationX,translationY);
    set.setDuration(3000);
    set.start();
    //旋转
 ObjectAnimator    objectAnimator =ObjectAnimator.ofFloat(home_iv_sport,"rotation",0f,360f);
    objectAnimator.setDuration(1000);
    objectAnimator.setRepeatCount(-1);
    objectAnimator.setRepeatMode(ValueAnimator.RESTART);

//组合
ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(home_iv_add, "alpha", 1.0f, 0.5f, 0.8f, 1.0f);
    ObjectAnimator scaleXAnim = ObjectAnimator.ofFloat(home_iv_add, "scaleX", 0.0f, 1.0f);
    ObjectAnimator scaleYAnim = ObjectAnimator.ofFloat(home_iv_add, "scaleY", 0.0f, 2.0f);
    ObjectAnimator rotateAnim = ObjectAnimator.ofFloat(home_iv_add, "rotation", 0, 360);
    ObjectAnimator transXAnim = ObjectAnimator.ofFloat(home_iv_add, "translationX", 100, 400);
    @SuppressLint("ObjectAnimatorBinding")
    ObjectAnimator transYAnim = ObjectAnimator.ofFloat(home_iv_add, "tranlsationY", 100, 750);
    AnimatorSet set = new AnimatorSet();
    set.playTogether(alphaAnim, scaleXAnim, scaleYAnim, rotateAnim, transXAnim, transYAnim);
      set.playSequentially(alphaAnim, scaleXAnim, scaleYAnim, rotateAnim, transXAnim, transYAnim);
    set.setDuration(3000);
    set.start();

补件动画

AlphaAnimation:透明度渐变效果,创建时许指定开始以及结束透明度,还有动画的持续 时间,透明度的变化范围(0,1),0是完全透明,1是完全不透明;对应<alpha/>标签!
ScaleAnimation:缩放渐变效果,创建时需指定开始以及结束的缩放比,以及缩放参考点, 还有动画的持续时间;对应<scale/>标签!
TranslateAnimation:位移渐变效果,创建时指定起始以及结束位置,并指定动画的持续 时间即可;对应<translate/>标签!
RotateAnimation:旋转渐变效果,创建时指定动画起始以及结束的旋转角度,以及动画 持续时间和旋转的轴心;对应<rotate/>标签
AnimationSet:组合渐变,就是前面多种渐变的组合,对应<set/>标签

AlphaAnimation(透明度渐变)

fromAlpha :起始透明度
toAlpha:结束透明度

<alpha xmlns:android="http://schemas.android.com/apk/res/android"  
android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
android:fromAlpha="1.0"  
android:toAlpha="0.1"  
android:duration="2000"/>

ScaleAnimation(缩放渐变)

fromXScale/fromYScale:沿着X轴/Y轴缩放的起始比例
toXScale/toYScale:沿着X轴/Y轴缩放的结束比例
pivotX/pivotY:缩放的中轴点X/Y坐标,即距离自身左边缘的位置,比如50%就是以图像的 中心为中轴点

<scale xmlns:android="http://schemas.android.com/apk/res/android"  
android:interpolator="@android:anim/accelerate_interpolator"  
android:fromXScale="0.2"  
android:toXScale="1.5"  
android:fromYScale="0.2"  
android:toYScale="1.5"  
android:pivotX="50%"  
android:pivotY="50%"  
android:duration="2000"/>

TranslateAnimation(位移渐变)

fromXDelta/fromYDelta:动画起始位置的X/Y坐标
toXDelta/toYDelta:动画结束位置的X/Y坐标

<translate xmlns:android="http://schemas.android.com/apk/res/android"  
android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
android:fromXDelta="0"  
android:toXDelta="320"  
android:fromYDelta="0"  
android:toYDelta="0"  
android:duration="2000"/>

RotateAnimation(旋转渐变)

fromDegrees/toDegrees:旋转的起始/结束角度
repeatCount:旋转的次数,默认值为0,代表一次,假如是其他值,比如3,则旋转4次 另外,值为-1或者infinite时,表示动画永不停止
repeatMode:设置重复模式,默认restart,但只有当repeatCount大于0或者infinite或-1时 才有效。还可以设置成reverse,表示偶数次显示动画时会做方向相反的运动!

<rotate xmlns:android="http://schemas.android.com/apk/res/android"  
android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
android:fromDegrees="0"  
android:toDegrees="360"  
android:duration="1000"  
android:repeatCount="1"  
android:repeatMode="reverse"/> 

AnimationSet(组合渐变)

<set xmlns:android="http://schemas.android.com/apk/res/android"  
android:interpolator="@android:anim/decelerate_interpolator"  
android:shareInterpolator="true" >  

<scale  
    android:duration="2000"  
    android:fromXScale="0.2"  
    android:fromYScale="0.2"  
    android:pivotX="50%"  
    android:pivotY="50%"  
    android:toXScale="1.5"  
    android:toYScale="1.5" />  

<rotate  
    android:duration="1000"  
    android:fromDegrees="0"  
    android:repeatCount="1"  
    android:repeatMode="reverse"  
    android:toDegrees="360" />  

<translate  
    android:duration="2000"  
    android:fromXDelta="0"  
    android:fromYDelta="0"  
    android:toXDelta="320"  
    android:toYDelta="0" />  

<alpha  
    android:duration="2000"  
    android:fromAlpha="1.0"  
    android:toAlpha="0.1" />  
	调用:
 Animation  animation = AnimationUtils.loadAnimation(this,
                    R.anim.anim_alpha);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

一声紫金,一生紫金

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

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

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

打赏作者

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

抵扣说明:

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

余额充值