本文以實例形式展現了Android實現Activity界面切換添加動畫特效的方法,對於Android程序設計人員來講有很好的參考借鑑價值。具體方法以下:android
瞭解Android程序設計的人應該知道,在Android 2.0以後有了overridePendingTransition(),其中裏面兩個參數,一個是前一個activity的退出,另外一個activity的進入。iphone
現看看下面這段示例代碼:ide
?post
1動畫 2this 3spa 4.net 5設計 6code 7 8 9 10 11 12 13 14 15 |
@Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.SplashScreen); new Handler().postDelayed( new Runnable() { @Override public void run() { Intent mainIntent = new Intent(SplashScreen. this , AndroidNews. class ); SplashScreen. this .startActivity(mainIntent); SplashScreen. this .finish(); overridePendingTransition(R.anim.mainfadein, R.anim.splashfadeout); } }, 3000 ); } |
上面的代碼只是閃屏的一部分。
?
1 |
getWindow().setWindowAnimations( int ); |
這可沒有上個好可是也能夠 。
實現淡入淡出的效果:
?
1 |
overridePendingTransition(Android.R.anim.fade_in,android.R.anim.fade_out); |
由左向右滑入的效果:
?
1 |
overridePendingTransition(Android.R.anim.slide_in_left,android.R.anim.slide_out_right); |
實現zoomin和zoomout,即相似iphone的進入和退出時的效果:
?
1 |
overridePendingTransition(R.anim.zoomin, R.anim.zoomout); |
新建zoomin.xml文件:
?
1 2 3 4 5 6 7 8 |
<? xml version = "1.0" encoding = "utf-8" ?> < set xmlns:Android = "http://schemas.android.com/apk/res/android" Android:interpolator = "@android:anim/decelerate_interpolator" > < scale Android:fromXScale = "2.0" android:toXScale = "1.0" Android:fromYScale = "2.0" android:toYScale = "1.0" Android:pivotX = "50%p" android:pivotY = "50%p" Android:duration = "@android:integer/config_mediumAnimTime" /> </ set > |
新建zoomout.xml文件:
?
1 2 3 4 5 6 7 8 9 10 11 |
<? xml version = "1.0" encoding = "utf-8" ?> < set xmlns:Android = "http://schemas.android.com/apk/res/android" Android:interpolator = "@android:anim/decelerate_interpolator" Android:zAdjustment = "top" > < scale Android:fromXScale = "1.0" android:toXScale = ".5" Android:fromYScale = "1.0" android:toYScale = ".5" Android:pivotX = "50%p" android:pivotY = "50%p" Android:duration = "@android:integer/config_mediumAnimTime" /> < alpha Android:fromAlpha = "1.0" android:toAlpha = "0" Android:duration = "@android:integer/config_mediumAnimTime" /> </ set > |
相信本文所述示例對你們的Android程序設計有必定的借鑑價值。
您可能感興趣的文章: