Android 实现属性动画平移,旋转,缩放,渐变 《H》

以下代码直接使用点击事件调用即可

平移

     ObjectAnimator translationX = new ObjectAnimator().ofFloat(myyuan,"translationX",0,600f);
     ObjectAnimator translationY = new ObjectAnimator().ofFloat(myyuan,"translationY",0,0);

     AnimatorSet animatorSet = new AnimatorSet();  //组合动画
     animatorSet.playTogether(translationX,translationY); //设置动画
     animatorSet.setDuration(3000);  //设置动画时间
     animatorSet.start(); //启动

旋转

   ObjectAnimator ra = ObjectAnimator.ofFloat(myyuan,"rotation", 0f, 360f);
   ra.setDuration(3000);
   ra.start();

缩放  

   AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画
   ObjectAnimator scaleX = ObjectAnimator.ofFloat(myyuan, "scaleX", 0, 1f);
   ObjectAnimator scaleY = ObjectAnimator.ofFloat(myyuan, "scaleY", 0, 1f);

   animatorSetsuofang.setDuration(2000);
   animatorSetsuofang.setInterpolator(new DecelerateInterpolator());
   animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始
   animatorSetsuofang.start();



渐变

  ObjectAnimator anim = ObjectAnimator.ofFloat(myyuan, "alpha", 1f, 0.1f, 1f, 0.5f, 1f);
  anim.setDuration(5000);// 动画持续时间
  anim.start();

动画监听事件

       //动画的监听
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {
		Log.d("动画开始","");
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                //动画结束跳转
                Intent intent = new Intent(MainActivity.this, Main2Activity.class);
                startActivity(intent);
            }

            @Override
            public void onAnimationCancel(Animator animator) {
		Log.d("动画取消","");
            }

            @Override
            public void onAnimationRepeat(Animator animator) {
		Log.d("动画重复","");
            }
        });





你可能感兴趣的:(Android 实现属性动画平移,旋转,缩放,渐变 《H》)