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

基本属性动画

程序员文章站 2022-06-09 10:34:21
...
				 //横向平移
                ObjectAnimator translationX = new ObjectAnimator().ofFloat(imageView,"translationX",0,0);
                //垂直平移
                ObjectAnimator translationY = new ObjectAnimator().ofFloat(imageView,"translationY",0,500f);
                //旋转
                ObjectAnimator ra = ObjectAnimator.ofFloat(imageView,"rotation", 0f, 360f);
                //缩放
                ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 0, 1f);
                ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 0, 1f);
                //渐变
                ObjectAnimator anim = ObjectAnimator.ofFloat(imageView, "alpha", 1f, 0.1f,1f, 0.5f, 1f);

                AnimatorSet animatorSet = new AnimatorSet(); //组合动画
                animatorSet.playTogether(translationX,translationY,ra,scaleX,scaleY,anim); //设置动画
                animatorSet.setDuration(3000);  //设置动画时间
                animatorSet.start(); //启动
                //设置动画的监听事件
                animatorSet.addListener(new AnimatorListenerAdapter() {
                    @Override
                    //终止
                    public void onAnimationCancel(Animator animation) {
                        super.onAnimationCancel(animation);
                    }

                    @Override
                    //结束
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        Intent intent = new Intent(SplashActivity.this,MainActivity.class);
                        startActivity(intent);
                    }

                    @Override
                    //重复
                    public void onAnimationRepeat(Animator animation) {
                        super.onAnimationRepeat(animation);
                    }

                    @Override
                    //开始
                    public void onAnimationStart(Animator animation) {
                        super.onAnimationStart(animation);
                    }
                });