zoukankan      html  css  js  c++  java
  • 安卓开发之之属性动画

    (内容省略了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();
  • 相关阅读:
    em与rem之间的区别以及移动设备中的rem适配方案
    关于两个DIV之间的空白字符
    Bootstrap基本模板
    js 裁剪
    记一次诡异的bug
    Node切换版本
    git 撤销
    使用 iframe + postMessage 实现跨域通信
    <el-input>标签限制输入小数点
    vue elementyUI table :点击一行时选中这一行对应的复选框
  • 原文地址:https://www.cnblogs.com/adressian/p/10776348.html
Copyright © 2011-2022 走看看