(2013-02-19 10:52:15)
标签: |
实现两个 Activity 切换时的动画。在Activity中使用
有两个参数:进入动画和出去的动画。注意
1、必须在 StartActivity() 或 finish() 之后立即调用。 2、而且在 2.1 以上版本有效 3、手机设置-显示-动画,要开启状态//实现淡入浅出的效果
startActivity(newIntent(MainActivity.this,SecondActivity.class)); overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);// 由左向右滑入的效果
startActivity(newIntent(MainActivity.this,SecondActivity.class)); overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);// 实现zoommin 和 zoomout (自定义的动画)
startActivity(newIntent(OverridePendingTransitionActivity.this,SecondActivity.class)); overridePendingTransition(R.anim.zoomin, R.anim.zoomout); anim/zoomin.xml <?xml version="1.0"encoding="utf-8"?> <set xmlns:android="" android:interpolator="@android:anim/decelerate_interpolator"> <scale android:duration="@android:integer/config_mediumAnimTime" android:fromXScale="0.1" android:fromYScale="0.1" android:pivotX="50%p" android:pivotY="50%p" android:toXScale="1.0" android:toYScale="1.0" /> <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="0" android:toAlpha="1.0" /> </set>anim/zoomout.xml
<?xml version="1.0"encoding="utf-8"?> <set xmlns:android="" android:interpolator="@android:anim/decelerate_interpolator" android:zAdjustment="top" > <scale android:duration="@android:integer/config_mediumAnimTime" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%p" android:pivotY="50%p" android:toXScale="0.1" android:toYScale="0.1" /> <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="1.0" android:toAlpha="0" /> </set>