欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

属性动画---平移、旋转、缩放、渐变、组合

程序员文章站 2022-05-02 22:14:47
...

布局—5个按钮,一个ImageView

平移

        private void transAnimator() {
            ObjectAnimator objectAnimator = new ObjectAnimator().ofFloat(image,
                    "translationX", 0f, 200f);
            //设置移动时间
            objectAnimator.setDuration(2000);
            //开始动画
            objectAnimator.start();
      }

旋转

private void rotateAnimator() {
        //创建属性动画,设置移动的方向和偏移量
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(image, "rotation", 0f, 360f);
        //设置移动时间
        objectAnimator.setDuration(2000);
        //开始动画
        objectAnimator.start();
    }

缩放

private void zoomAnimator() {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(image,
                "scaleY", 5f, 5f, 1f);
        objectAnimator.setDuration(5000);
        objectAnimator.start();
    }

渐变

private void gradualAnimator() {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(image, "alpha", 0f, 1f);
        objectAnimator.setDuration(1000);
        objectAnimator.start();
    }

组合

private void allAnimator() {
        ObjectAnimator objectAnimatorX = ObjectAnimator.ofFloat(image,
                "translationX", 0f, 200f);
        ObjectAnimator objectAnimatorY = ObjectAnimator.ofFloat(image,
                "translationY", 0f, 200f);
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(image,
                "rotation", 0f, 360f);
        AnimatorSet animatorSet=new AnimatorSet();
        animatorSet.play(objectAnimatorX).with(objectAnimatorY);
        animatorSet.play(objectAnimator).after(objectAnimatorX);
        animatorSet.setDuration(1000);
        animatorSet.start();
    }
相关标签: 属性动画