• 安卓开发之之属性动画


    (内容省略了valueAnimator和PropertyValueHolder使用)

    属性动画的使用的主要方式是AnimatorSet和ObjectAnimator配合使用.ObjectAnimator控制一个对象和一个属性,多个ObjectAnimator组合到AnimatorSet可以实现丰富的动画效果.

    一.ObjectAnimator单独使用

    ObjectAnimator mobjectAnimator=ObjectAnimator.ofFloat(view,"translationX",200);
                    mobjectAnimator.setDuration(300);
                    mobjectAnimator.start();

    除了设置时长以外,还可以设置插值器.其可以常用的直接使用的属性动画属性值有:

    translationX,translationY//平移

    rotation,rotationX,rotationX//旋转

    PrivotX,PrivotY//支点

    alpha//透明度

    x,y//View最终位置

    二.监听动画过程

    mobjectAnimator.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {
                        }
    
                        @Override
                        public void onAnimationEnd(Animator animation) {
    
                        }
    
                        @Override
                        public void onAnimationCancel(Animator animation) {
    
                        }
    
                        @Override
                        public void onAnimationRepeat(Animator animation) {
    
                        }
                    });

    三.组合动画

    AnimatorSet使用play(Animator anim)传入动画

    并且通过以下方法插入新动画:

      after(Animator anim)

      after(long delay)//延迟指定毫秒后执行

      with(Animator anim)

      before(Animator anim)

                    ObjectAnimator Animator1 = ObjectAnimator.ofFloat(view, "translationX", 200);
                    ObjectAnimator Animator2 = ObjectAnimator.ofFloat(view, "ScaleX", 1.0f, 2.0f);
                    ObjectAnimator Animator3 = ObjectAnimator.ofFloat(view, "rotationX", 0.0f, 90.0f);
                    AnimatorSet set=new AnimatorSet();
                    set.setDuration(2000);
                    set.play(Animator1).with(Animator2).after(Animator3);
                    set.start();
  • 相关阅读:
    css如何设置div中的内容垂直居中?
    有哪些sql优化工具
    XSS攻击
    java的HashSet 原理
    复杂度O(n)计算
    Kubernetes(K8s)基础知识(docker容器技术)
    Golang glog使用详解
    教你如何找到Go内存泄露【精编实战】
    Linux生产环境上,最常用的一套“AWK“技巧【转】
    Go 程序的性能监控与分析 pprof
  • 原文地址:https://www.cnblogs.com/adressian/p/10776348.html
Copyright © 2020-2023  润新知