public void openActivity(View v){Intent intent = new Intent(this, OtherActivity.class);
startActivity(intent);
//屏幕动画淡入淡出效果切换,调用anim文件夹中创建的enteralpha(进入动画)和exitalpha(淡出动画)两个动画(注意:两个xml文件命名不能有大写字母)
//如果想定义其他动画效果,只需要改变enteralpha和exitalpha两个文件
this.overridePendingTransition(R.anim.enteralpha,R.anim.exitalpha);
}
其中,enteralpha.xml为
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <!-- 动画效果 从看不见到可以看见,也就是0到1,变幻时间为5000毫秒--> <alpha android:fromAlpha="0" android:toAlpha="1" android:duration="5000" /> </set>
exitalpha.xml为
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <!-- 退出动画效果 从可以看见到不可以看见,也就是1.0到0,变幻时间为5000毫秒--> <alpha android:fromAlpha="1.0" android:toAlpha="0" android:duration="5000" /> </set>