Android动画使用记录

一、常用动画类

暂分为两类:

1、Animation
  • TranslateAnimation 位移动画
//fromXDelta,fromYDelta起始坐标
//toXDelta,toYDelta 移动坐标
TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta);
  • AlphaAnimation 透明动画
//fromAlpha 起始透明度,toAlpha 最终透明度
AlphaAnimation(float fromAlpha, float toAlpha) 
  • ScaleAnimation 缩放动画
ScaleAnimation(float fromX, float toX, float fromY, float toY)
  • AnimationSet
2、Animator
  • ViewAnimator
ofInt(Object target, String propertyName, int... values)
ofFloat(Object target, String propertyName, float... values) 
ofObject(Object target, String propertyName,
            TypeEvaluator evaluator, Object... values) 
ofPropertyValuesHolder(Object target,
            PropertyValuesHolder... values)
  • ObjectAnimator

  • AnimatorSet

二、 Animator使用注意

  • 一个ObjectAnimator多个动画复合
    通过PropertyValuesHolder构建ObjectAnimator,如:
float tranX = getResources().getDimension(R.dimen._20dp);
float tranY = getResources().getDimension(R.dimen._10dp);

PropertyValuesHolder valuesHolderX = PropertyValuesHolder.ofFloat("translationX", 0.0f, -tranX);
PropertyValuesHolder valuesHolderY = PropertyValuesHolder.ofFloat("translationY", 0.0f, -tranY);

final ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(mTarget, valuesHolderX, valuesHolderY);
  • Animator如何恢复默认值
    通过Traget的setXXX方法设置相关默认值,如:
 mTarget.setAlpha(1.0f);
 mTarget.setTranslationX(0);
 mTarget.setTranslationY(0);
  • Animator监听器
    Animator的监听器常用的有2种:
    1、Animator.AnimatorListener 动画关键性的动作回调
    2、AnimatorUpdateListener 动画更新的回调
public void addUpdateListener(AnimatorUpdateListener listener){}

   public static interface AnimatorUpdateListener {
        /**
         * <p>Notifies the occurrence of another frame of the animation.</p>
         *
         * @param animation The animation which was repeated.
         */
        void onAnimationUpdate(ValueAnimator animation);

    }

public void addListener(AnimatorListener listener) {}

public static interface AnimatorListener {
        /**
         * <p>Notifies the start of the animation.</p>
         *
         * @param animation The started animation.
         */
        void onAnimationStart(Animator animation);

        /**
         * `注意`如果动画有设置Repeat,则Repeat结束后最后才回调onAnimationEnd
         * <p>Notifies the end of the animation. This callback is not invoked
         * for animations with repeat count set to INFINITE.</p>
         *
         * 
         * @param animation The animation which reached its end.
         */
        void onAnimationEnd(Animator animation);

        /**
         * <p>Notifies the cancellation of the animation. This callback is not invoked
         * for animations with repeat count set to INFINITE.</p>
         *
         * @param animation The animation which was canceled.
         */
        void onAnimationCancel(Animator animation);

        /**
         * 
         * <p>Notifies the repetition of the animation.</p>
         *
         * @param animation The animation which was repeated.
         */
        void onAnimationRepeat(Animator animation);
    }

三、其他

AnimationSet和AnimatorSet的区别:
AnimationSet 多个Animation动画同时进行,动画播放顺序不可控制。
AnimatorSet 多个Animator动画可以选择顺序也可同时进行,播放顺序不可控制。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值