Android Activity界面切换添加动画特效 (修改)

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

前一个Activity    SplashScreen:

@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		new Handler().postDelayed(new Runnable(){
			@Override
			public void run() {
				Intent intent = new Intent(SplashScreen.this, NextActivity.class);
				SplashScreen.this.startActivity(intent);
				SplashScreen.this.finish();
                                //添加页面切换效果,留意只有android2.0(SDKVersion版本号为5)以后的版本才支持
				int version = Integer.valueOf(android.os.Build.VERSION.SDK);
				if(5 <= version){
				     //淡入淡出效果
				     //overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
				     //由左向右滑入
	          	             //overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
				     //Ipone式的切换效果,自定义 zoomin.xml,zoomout.xml
				     overridePendingTransition(R.anim.zoomin,R.anim.zoomout);
                                    //getWindow ().setWindowAnimations ( int );
                                  //这可没有上个好但是也可以 。
                                }
			}
		}, 3000);
	}
res/anim/zoomin.xml:

<?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>

res/anim/zoomout.xml:

<?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>





你可能感兴趣的:(Activity)