手势下一步上一步时,产生translate动画效果
1、anim文件夹名字不可改变,固定的。\res\anim\2、定义上一步和下一步动画文件 a) tran_next_out.xml <?xml version="1.0" encoding="utf-8"?>
<!-- 1、下一步,屏幕出去动画 -->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="-100%p"
android:toYDelta="0" /> b) tran_next_in.xml <?xml version="1.0" encoding="utf-8"?>
<!-- 2、下一步,屏幕进入动画 -->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="100%p"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="0" /> c) tran_pre_out.xml <?xml version="1.0" encoding="utf-8"?>
<!-- 3、上一步,屏幕出去动画 -->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="100%p"
android:toYDelta="0" /> d) tran_pre_in.xml <?xml version="1.0" encoding="utf-8"?>
<!-- 4、上一步,屏幕进入动画 -->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="-100%p"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="0" /> //Call immediately after one of the flavors of startActivity(Intent) or finish to specify an explicit transition animation to perform next. //startActivity(Intent)和finish调用 WizardSetupActivity3.java @Override
public void next(View view) {
Intent intent = new Intent(this, WizardSetupActivity4.class);
startActivity(intent);
this.finish();
overridePendingTransition(R.anim.tran_next_in, R.anim.tran_next_out);
}
@Override
public void previous(View view) {
Intent intent = new Intent(this, WizardSetupActivity2.class);
startActivity(intent);
this.finish();
overridePendingTransition(R.anim.tran_pre_in, R.anim.tran_pre_out);
} 4、一定要在动画文件中设置动画播放的时间: android:duration="300" 5、华为手机可能不能播放动画,默认关闭了动画,可以在开发者选项中开启 |
动画下一步的分析图解: |
结果: |