Android Activity界面切换添加动画特效

在Android 2.0之后有了void android.app.Activity.overridePendingTransition(int enterAnim, int exitAnim),其中里面两个参数,一个是前一个activity的退出另一个是后一个activity的进入。

前一个Activity    SplashScreen:

[java]  view plain copy print ?
  1. @Override  
  2.     protected void onCreate(Bundle savedInstanceState) {  
  3.         super.onCreate(savedInstanceState);  
  4.         setContentView(R.layout.main);  
  5.           
  6.         new Handler().postDelayed(new Runnable(){  
  7.             @Override  
  8.             public void run() {  
  9.                 Intent intent = new Intent(SplashScreen.this, NextActivity.class);  
  10.                 SplashScreen.this.startActivity(intent);  
  11.                 SplashScreen.this.finish();  
  12.                                 //添加页面切换效果,留意只有android2.0(SDKVersion版本号为5)以后的版本才支持  
  13.                 int version = Integer.valueOf(android.os.Build.VERSION.SDK);  
  14.                 if(5 <= version){  
  15.                      //淡入淡出效果  
  16.                      //overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);  
  17.                      //由左向右滑入  
  18.                              //overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);  
  19.                      //Ipone式的切换效果,自定义 zoomin.xml,zoomout.xml  
  20.                      overridePendingTransition(R.anim.zoomin,R.anim.zoomout);  
  21.                                     //getWindow ().setWindowAnimations ( int );  
  22.                                   //这可没有上个好但是也可以 。  
  23.                                 }  
  24.             }  
  25.         }, 3000);  
  26.     }  
res/anim/zoomin.xml:

[html]  view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:interpolator="@android:anim/decelerate_interpolator">  
  4.     <scale android:fromXScale="2.0" android:toXScale="1.0"  
  5.         android:fromYScale="2.0" android:toYScale="1.0"  
  6.         android:pivotX="50%p" android:pivotY="50%p"  
  7.         android:duration="@android:integer/config_mediumAnimTime"  
  8.         />  
  9. </set>  

res/anim/zoomout.xml:

[html]  view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:interpolator="@android:anim/decelerate_interpolator"  
  4.     android:zAdjustment="top">  
  5.     <scale android:fromXScale="1.0" android:toXScale=".5"  
  6.         android:fromYScale="1.0" android:toYScale=".5"  
  7.         android:pivotX="50%p" android:pivotY="50%p"  
  8.         android:duration="@android:integer/config_mediumAnimTime"  
  9.         />  
  10.     <alpha android:fromAlpha="1.0" android:toAlpha="0"  
  11.         android:duration="@android:integer/config_mediumAnimTime"  
  12.         />  
  13. </set>  



原文地址:http://blog.csdn.net/repoem/article/details/7003596

你可能感兴趣的:(Android Activity界面切换添加动画特效)