片段交易中的自定义动画无效

时间:2013-11-08 10:31:42

标签: android animation fragment

MFragment fragment = new MFragment();
final FragmentTransaction fragmentTransaction = fragmentManager
                    .beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_in_right,
        R.anim.slide_out_left, R.anim.slide_in_left,
        R.anim.slide_out_right);
fragmentTransaction.add(R.id.container, fragment,
        "frag1");
fragmentTransaction.commit();

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        MFragment fragment = new MFragment();
        final FragmentTransaction fragmentTransaction = fragmentManager
                .beginTransaction();
        fragmentTransaction.setCustomAnimations(R.anim.slide_in_right,
                R.anim.slide_out_left, R.anim.slide_in_left,
                R.anim.slide_out_right);
        fragmentTransaction.replace(R.id.container, fragment)
                .addToBackStack("frag2");
        fragmentTransaction.commit();
    }
}, 3000);

当我加载FragmentActivity并添加 frag1 时,添加了适当的动画,从右向左滑动

但第二个片段 frag2 应该替换 frag1 会产生淡入/淡出动画,默认为。当我按下后退按钮时, frag2会以淡入淡出的动画弹出而不是从左向右滑出

动画/ slide_in_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="200"
        android:fromXDelta="100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />

</set>

0 个答案:

没有答案