答案 0 :(得分:3)
在res文件夹中创建一个名为anim的文件夹,并将以下xml文件复制到anim文件夹。
pull_in_right.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="100%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="0%" />
push_out_righ.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="-100%" />
并将以下代码添加到您的第二个活动onCreate()
overridePendingTransition(R.anim.pull_in_right,
R.anim.push_out_left);
答案 1 :(得分:0)
创建一个覆盖这两个方法的Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.overridePendingTransition(R.anim.animation_slide_in_right, R.anim.animation_slide_out_left);
}
public void onBackPressed() {
super.onBackPressed();
this.overridePendingTransition(R.anim.animation_slide_in_left, R.anim.animation_slide_out_right);
}
任何想要拥有幻灯片动画的活动都需要扩展此类。
animation_slide_in_right.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXDelta="100%p" android:toXDelta="0"
android:duration="@android:integer/config_shortAnimTime"/>
animation_slide_out_left.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXDelta="0" android:toXDelta="-100%"
android:duration="@android:integer/config_shortAnimTime"/>
animation_slide_in_left.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXDelta="-100%p" android:toXDelta="0"
android:duration="@android:integer/config_shortAnimTime"/>
animation_slide_out_right.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXDelta="0" android:toXDelta="100%"
android:duration="@android:integer/config_shortAnimTime"/>