overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
第一参数为进入的动画
第二参数为退出的动画
进入的动画
slide_in_right.xml
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="20" android:fromXDelta="100%" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toXDelta="0"> </translate>
slide_out_left.xml
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="20" android:fromXDelta="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toXDelta="-100%"> </translate>
退出的动画
slide_in_left.xml
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="20" android:fromXDelta="-100%" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toXDelta="0"> </translate>
slide_out_right.xml
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="20" android:fromXDelta="0%" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toXDelta="100%"> </translate>
用法:进入的动画
Intent intnet = new Intent(this,SecondActivity.class); startActivity(intnet); overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
退出的动画
finish();
overridePendingTransition(R.anim.slide_in_left,R.anim.slide_out_right);