我只需要简单的幻灯片并滑出动画片段转换,下面是我的代码:slide_in_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="700">
</translate>
</set>
Run Code Online (Sandbox Code Playgroud)
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700">
</translate>
</set>
Run Code Online (Sandbox Code Playgroud)
我用的代码:
SomeFragment frag = SomeFragment.newInstance(foo);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
ft.replace(R.id.the_fragment, frag);
ft.addToBackStack(null);
ft.commit();
Run Code Online (Sandbox Code Playgroud)
结果看起来非常奇怪,当转换开始时,当前片段消失而没有动画,输入片段(从左侧)像滚动纸一样.我的动画xml代码出了什么问题?
谢谢!