android overridePendingTransition Activty切換效果


很簡單,在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>

轉自:http://www.cnblogs.com/jiayonghua/archive/2012/04/17/2454225.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM