Android Tween Animations(动画效果)的使用

package lxy.litsoft;      import Android.app.Activity;   import android.os.Bundle;   import android.view.View;   import android.view.View.OnClickListener;   import android.view.animation.AlphaAnimation;   import android.view.animation.Animation;   import android.view.animation.AnimationSet;   import android.view.animation.RotateAnimation;   import android.view.animation.ScaleAnimation;   import android.view.animation.TranslateAnimation;   import android.widget.Button;   import android.widget.ImageView;      public class AppMain extends Activity {              //声明对象        private ImageView imageView;       private Button btAlpha;       private Button btScale;       private Button btRotate;       private Button btTranslate;              public void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.main);                      //实例化对象            imageView = (ImageView)findViewById(R.id.imageView01);                      btAlpha = (Button)findViewById(R.id.button01);           btAlpha.setOnClickListener(new ButtonListener());                      btScale = (Button)findViewById(R.id.button02);           btScale.setOnClickListener(new ButtonListener());                      btRotate = (Button)findViewById(R.id.button03);           btRotate.setOnClickListener(new ButtonListener());                      btTranslate = (Button)findViewById(R.id.button04);           btTranslate.setOnClickListener(new ButtonListener());       }              class ButtonListener implements OnClickListener{              public void onClick(View v) {               if(v.getId() == R.id.button01){ //Alpha:淡入淡出效果                    //创建AnimationSet对象                    AnimationSet animationSet = new AnimationSet(true);                    //从透明度1,到透明度0                    AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);                   //动画执行时间                    alphaAnimation.setDuration(1000);                      //把动画添加到动画集中                    animationSet.addAnimation(alphaAnimation);                     //把动画绑定控件                    imageView.startAnimation(animationSet);                                    btAlpha.startAnimation(animationSet);                                  } else if(v.getId() == R.id.button02){  //Scale:缩放效果                    AnimationSet animationSet = new AnimationSet(true);                   ScaleAnimation scaleAnimation = new ScaleAnimation(1,1,0,1,                           Animation.RELATIVE_TO_SELF,0.5f,                           Animation.RELATIVE_TO_SELF,0.5f);                   scaleAnimation.setDuration(1000);                   animationSet.addAnimation(scaleAnimation);                   imageView.startAnimation(animationSet);                   btScale.startAnimation(animationSet);                                  } else if(v.getId() == R.id.button03){  //Rotate:旋转效果                    AnimationSet animationSet = new AnimationSet(true);                   RotateAnimation rotateAnimation = new RotateAnimation(0f,360f,//旋转角度的变化范围                            Animation.RELATIVE_TO_SELF, 0.5f,       //旋转中心X的位置确定                            Animation.RELATIVE_TO_SELF,0.5f);       //旋转中心Y的位置确定                    rotateAnimation.setDuration(1000);                   animationSet.addAnimation(rotateAnimation);   //              imageView.startAnimation(animationSet);                    btRotate.startAnimation(animationSet);               }else if(v.getId() == R.id.button04){   //Translate:移动效果                    AnimationSet animationSet = new AnimationSet(true);                   TranslateAnimation translateAnimation = new TranslateAnimation(                           Animation.RELATIVE_TO_SELF, 1,                           Animation.RELATIVE_TO_SELF,0,                           Animation.RELATIVE_TO_SELF,1,                           Animation.RELATIVE_TO_SELF,0);                   translateAnimation.setDuration(1000);                   animationSet.addAnimation(translateAnimation);                   imageView.startAnimation(animationSet);                   btTranslate.startAnimation(animationSet);               }           }       }   }  

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwgysz.html