android动画(Animation)

AlphaAnimation 透明度

AlphaAnimationalphaAnimation = new AlphaAnimation(0, 1);

           alphaAnimation.setDuration(1000);

           alphaButton.startAnimation(alphaAnimation);

 

<?xml version="1.0"encoding="utf-8"?>

<alpha xmlns:android="http://schemas.android.com/apk/res/android"

    android:fromAlpha="0"

    android:toAlpha="1"

    android:duration="1000">

</alpha>

 

RotateAnimation 角度

//RotateAnimation rotateAnimation = new RotateAnimation(0, 360, 50,

           // 50);//50,50是相对控件自身的XY偏移量

           RotateAnimationrotateAnimation = new RotateAnimation(0, 360,

                  Animation.RELATIVE_TO_SELF, 0.5f,// 旋转点X坐标相对于自身比例一半的位置

                  Animation.RELATIVE_TO_SELF, 0.5f);

           rotateAnimation.setDuration(1000);

           rotateButton.startAnimation(rotateAnimation);

           // 调用Xml资源

           rotateButton.startAnimation(AnimationUtils.loadAnimation(

                  MainActivity.this, R.anim.ro));

 

<?xml version="1.0"encoding="utf-8"?>

<rotate xmlns:android="http://schemas.android.com/apk/res/android"

    android:fromDegrees="0"

    android:toDegrees="360"

    android:duration="1000"

    android:pivotX="50%"

    android:pivotY="50%">

</rotate>

 

ScaleAnimation 缩放

ScaleAnimationscaleAnimation = new ScaleAnimation(1, 1.5f, 1, 2,//x方向由1放大到1.5,y方向由1放大到2

                  Animation.RELATIVE_TO_SELF, 0.5f,//放大中心点X坐标在一半处

                  Animation.RELATIVE_TO_SELF, 0.5f);

           scaleAnimation.setDuration(1000);

           scaleButton.startAnimation(scaleAnimation);

          

           scaleButton.startAnimation(AnimationUtils.loadAnimation(

                  MainActivity.this, R.anim.sc));

 

<?xml version="1.0"encoding="utf-8"?>

<scale xmlns:android="http://schemas.android.com/apk/res/android"

    android:duration="1000"

    android:fromXScale="1"

    android:fromYScale="1"

    android:pivotX="50%" xml文件中相对比例用百分比

    android:pivotY="50%"

    android:toXScale="1.5"

    android:toYScale="2">

</scale>

 

TranslateAnimation 平移

TranslateAnimationtranslateAnimation = new TranslateAnimation(30,

                  200, 50, 100);// 移动x30200, 移动y方向从50100, 都是相对像素

           translateAnimation.setDuration(1000);

           transButton.startAnimation(translateAnimation);

 

           transButton.startAnimation(AnimationUtils.loadAnimation(

                  MainActivity.this, R.anim.tr));

 

<?xml version="1.0"encoding="utf-8"?>

<translate xmlns:android="http://schemas.android.com/apk/res/android"

    android:duration="1000"

    android:fromXDelta="30"

    android:fromYDelta="50"

    android:toXDelta="200"

    android:toYDelta="100">

</translate>

 

多个Animation组合

AnimationSet animationSet=new AnimationSet(true);

           animationSet.addAnimation(rotateAnimation);

           rotateButton.startAnimation(animationSet);

 

 

 

动画监听

rotateAnimation.setAnimationListener(new AnimationListener() {

             

              @Override

              public void onAnimationStart(Animation arg0) {

                 

              }

             

              @Override

              public void onAnimationRepeat(Animation arg0) {

                 

              }

             

              @Override

              public void onAnimationEnd(Animation arg0) {

                 

              }

           });

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值