很简单,在startActivity后,调用overridePendingTransition方法,例如,实现淡入淡出的效果如下:

 

 

view plain

  1. Intent i = new Intent(StartActivity.this,MainTab.class); 
  2. StartActivity.this.startActivity(i); 
  3. overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out); 

 

由左向右滑入的效果改变一下参数即可,

 

 

view plain

  1. overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right); 

 

以上是直接使用android.R.anim预先定义好的animation,很奇怪为什么没有zoomin和zoomout(也许是我没有找到,还望高人指点)

要实现zoomin和zoomout,即类似iphone的进入和退出时的效果,代码如下:

 

 

view plain

  1. overridePendingTransition(R.anim.zoomin, R.anim.zoomout); 

添加此代码后,eclipse会报错,因为没有zoomin和zoomout的定义

此时在res目录下新建文件夹anim,然后在anim下新建两个xml,默认选项不用更改,分别命名为zoomin.xml和zoomout.xml,

代码如下:

zoomin

 

 

view plain

  1. <?xmlversion="1.0"encoding="utf-8"?> 
  2. <setxmlns:android="http://schemas.android.com/apk/res/android" 
  3.         android:interpolator="@android:anim/decelerate_interpolator"> 
  4.     <scaleandroid: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. </set> 

 

zoomout

 

 

view plain

  1. <?xmlversion="1.0"encoding="utf-8"?> 
  2. <setxmlns:android="http://schemas.android.com/apk/res/android" 
  3.         android:interpolator="@android:anim/decelerate_interpolator" 
  4.         android:zAdjustment="top"> 
  5.     <scaleandroid: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.     <alphaandroid:fromAlpha="1.0"android:toAlpha="0" 
  10.             android:duration="@android:integer/config_mediumAnimTime"/> 
  11. </set>