如何在动画时将输入片段显示在退出片段上方。

问题描述 投票:0回答:3

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

我不想为旧片段设置动画,只需保持旧片段不变,当它可见时,将新片段向上滑动到其上方。

下面是我的代码:

// 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
3个回答
1
投票

你可以尝试用add()代替replace()来达到你想要的效果。希望这对您有帮助。


0
投票

新片段应该有一个像这样的输入动画(您可能已经在这样做了): 输入.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" />


0
投票

如果您想在下面设置 exit 片段,在顶部设置 enter 片段,请使用此 android:elevation="@dimen/_30sdp" 在根布局中 在你输入的片段中

© www.soinside.com 2019 - 2024. All rights reserved.