android 属性动画(缩放,渐变,移动,旋转)

首先设置一个图片,引入布局


第二步:初始化initData()

getSupportActionBar().hide();//隐藏标题栏
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();//这个好像是可以获取屏幕高度
        int height = displayMetrics.heightPixels;//获取屏幕高度
        //缩放---ofFloat用4个参数的ofFloat
        ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(iv_splash, "scaleX", 2, 1);
        //渐变
        ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(iv_splash, "alpha", 0, 1);
        //旋转
        ObjectAnimator objectAnimator3 = ObjectAnimator.ofFloat(iv_splash, "rotation", 0, 360);
        //移动
        ObjectAnimator objectAnimator4 = ObjectAnimator.ofFloat(iv_splash, "translationY", 0, height / 2 - iv_splash.getHeight() / 2);

        //组合
        AnimatorSet set = new AnimatorSet();
         /**
         * 动画执行
         */
        set.play(objectAnimator1).with(objectAnimator2).with(objectAnimator3).with(objectAnimator4);
        set.setDuration(3000);
        set.start();

第三步:给动画添加监听

/**
         * 动画执行的监听
         */
        set.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }
            //动画执行完后跳转到主activity
            @Override
            public void onAnimationEnd(Animator animation) {
                Intent intent = new Intent(MainActivity.this,Main2Activity.class);
                startActivity(intent);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

你可能感兴趣的:(android 属性动画(缩放,渐变,移动,旋转))