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

布局—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();
    }

猜你喜欢

转载自blog.csdn.net/WhuiQi/article/details/84074336