片段事务动画叠加

5
我正在尝试在使用fragment transactionreplace()时使用动画。我使用setCustomAnimations()设置动画。 我的animation试图将从右侧移动的新fragment与旧fragment重叠。但问题是:即使新fragment已经覆盖了旧的fragment,我仍然可以看到旧的views。只有当动画完成后,旧的views才会消失。此外,当一个新的fragment是一个复杂的listviews等时,我可以看到一些伪像和闪烁。 这太可怕了,我该如何避免这种情况?
我的进入animation代码:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:ordering="together">


  <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:propertyName="x" 
    android:valueType="floatType"
    android:valueTo="0" 
    android:valueFrom="720"
    android:duration="250"
    android:zAdjustment="top"/>  

</set>
更新:关于工件的问题-不是它们。这只是错误叠加的后果。我观看了动画慢慢地。
因此,问题在于:旧片段保持在最上层,并在动画过程中完全覆盖新片段。

可能是ugly fragment transition to surfaceview with overlay的重复问题。 - Jesus Angulo
1
我没有SurfaceView,而且在所有片段上重叠都不好,不仅是困难的片段(带有列表视图)。 - T.Vert
2个回答

1

如果您的新片段没有设置背景,这可能会导致您所说的奇怪外观。如果是这种情况,请在新片段上设置一个与第一个重叠的背景颜色。

android:background="@drawable/background"

1
你的问题是因为在进入和退出动画中使用了相同的动画文件,你需要为旧片段设置不同于进入片段的退出动画,例如向另一侧。 transaction.setCustomAnimations(<enterAnimationResId>, <exitAnimationResId>); 其中enterAnimationResId 是一个包含应用于进入片段的动画的xml文件,而exitAnimationResId 是一个包含应用于关闭现有片段的动画的xml文件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接