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("动画重复","");
            }
        });





发布了33 篇原创文章 · 获赞 5 · 访问量 4万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览