【问题标题】:How to show enter fragment above exit fragment while animating.动画时如何在退出片段上方显示进入片段。
【发布时间】:2015-01-09 06:37:40
【问题描述】:

我想要实现的效果是将进入(新)片段覆盖在退出(旧)片段上方, 但是当我用新片段替换旧片段时,旧片段消失了,新片段滑到容​​器上,这是可见的(容器)。

我不想为旧片段设置动画,只是保持旧片段保持原样,当它可见时将新片段向上滑动。

下面是我的代码:

// First time adding fragment i.e. "oldFragemnt"
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, oldFragment, "oldFragemnt");
ft.addToBackStack(null);
ft.commit();

// while adding "newFragemnt"
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.new_slide_in_up,0,0,R.anim.new_slide_out_down);                                   
ft.replace(R.id.content_frame, newFragment, "newFragemnt");
ft.addToBackStack(null);
ft.commit();

指导我哪里出错了。我的旧片段正在消失,而新片段正在向上滑动。

【问题讨论】:

标签: android android-fragments android-animation fragmenttransaction


【解决方案1】:

你可以尝试将replace()替换成add()来达到你想要的效果。希望这会对你有所帮助。

【讨论】:

    【解决方案2】:

    新片段应该有一个像这样的进入动画(你可能已经这样做了): enter.xml

    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    
    <translate
        android:duration="400"
        android:fromXDelta="90%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%"
        android:zAdjustment="top" />
    

    旧片段应该像hold一样留在同一个地方。 hold.xml

    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    
    <translate
        android:duration="400"
        android:zAdjustment="bottom" />
    

    【讨论】:

    • 我的旧片段仍然不可见
    • 我不希望旧片段动画,它应该在背景中可见,直到新片段向上滑动。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-11
    • 2015-06-28
    相关资源
    最近更新 更多