相关疑难解决方法(0)

嵌套片段转换不正确

你好堆栈溢出的程序员!我已经度过了这个问题的好一周,现在我非常渴望一个解决方案.


场景

我正在使用android.app.Fragment,不要与支持片段混淆.

我有6个子片段命名为:

  • FragmentOne
  • FragmentTwo
  • FragmentThree
  • FragmentA
  • FragmentB
  • FragmentC

我有2个父片段命名:

  • FragmentNumeric
  • FragmentAlpha

我有1个名为的活动:

  • MainActivity

他们表现如下:

  • 子片段是仅显示视图的片段,它们不显示也不包含片段.
  • 父片段使用单个子片段填充其整个视图.他们能够用其他子片段替换子片段.
  • 该活动使用父片段填充其大部分视图.它可以用其他父片段替换它.因此,在任何时候屏幕只显示一个子片段.

你可能已经猜到了,

FragmentNumeric显示子片段FragmentOne,FragmentTwoFragmentThree.

FragmentAlpha显示子片段FragmentA,FragmentBFragmentC.


问题

我正在尝试过渡/动画父母和子女片段.儿童片段按预期顺利过渡.但是,当我转换到新的父片段时,它看起来很糟糕.子片段看起来像是从其父片段运行独立过渡.并且子片段看起来也像是从父片段中删除的.它的gif可以在这里查看https://imgur.com/kOAotvk.注意单击Show Alpha时会发生什么.

我能找到的最接近的问题和答案是:嵌套片段在过渡动画期间消失,但所有答案都不满意.


动画XML文件

我有以下动画效果(持续时间很长,用于测试目的):

fragment_enter.xml

<?xml version="1.0" encoding="utf-8"?>
<set>
    <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="4000"
        android:interpolator="@android:anim/linear_interpolator"
        android:propertyName="xFraction"
        android:valueFrom="1.0"
        android:valueTo="0" />
</set>
Run Code Online (Sandbox Code Playgroud)

fragment_exit.xml

<?xml version="1.0" encoding="utf-8"?>
<set>
    <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="4000"
        android:interpolator="@android:anim/linear_interpolator"
        android:propertyName="xFraction"
        android:valueFrom="0"
        android:valueTo="-1.0" />
</set>
Run Code Online (Sandbox Code Playgroud)

fragment_pop.xml

<?xml version="1.0" encoding="utf-8"?> …
Run Code Online (Sandbox Code Playgroud)

android android-fragments fragmenttransaction android-nested-fragment fragment-animation

18
推荐指数
1
解决办法
1204
查看次数