android动画(Animation)

来源:互联网 发布:suse11 linux iso下载 编辑:程序博客网 时间:2024/06/05 05:48

AlphaAnimation 透明度

AlphaAnimationalphaAnimation = new AlphaAnimation(0, 1);

           alphaAnimation.setDuration(1000);

           alphaButton.startAnimation(alphaAnimation);

 

<?xmlversion="1.0"encoding="utf-8"?>

<alphaxmlns: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));

 

<?xmlversion="1.0"encoding="utf-8"?>

<rotatexmlns: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));

 

<?xmlversion="1.0"encoding="utf-8"?>

<scalexmlns: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));

 

<?xmlversion="1.0"encoding="utf-8"?>

<translatexmlns: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
原创粉丝点击