在过渡动画嵌套片段消失 [英] Nested fragments disappear during transition animation

查看:140
本文介绍了在过渡动画嵌套片段消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的情景:活动包含片段 A ,从而使用 getChildFragmentManager()添加片段 A1 A2 的onCreate 像这样:

Here's the scenario: Activity contains fragment A, which in turn uses getChildFragmentManager() to add fragments A1 and A2 in its onCreate like so:

getChildFragmentManager()
  .beginTransaction()
  .replace(R.id.fragmentOneHolder, new FragmentA1())
  .replace(R.id.fragmentTwoHolder, new FragmentA2())
  .commit()

到目前为止,一切都很好,一切都按预期运行。

So far, so good, everything is running as expected.

我们再运行下列事务中的活动:

We then run the following transaction in the Activity:

getSupportFragmentManager()
  .beginTransaction()
  .setCustomAnimations(anim1, anim2, anim1, anim2)
  .replace(R.id.fragmentHolder, new FragmentB())
  .addToBackStack(null)
  .commit()

在过渡期间,在输入动画片段 B 正常运行,但片段A1和A2消失完全。当我们恢复交易的后退按钮,就正确初始化和显示正常的 popEnter 动画过程中。

During the transition, the enter animations for fragment B runs correctly but fragments A1 and A2 disappear entirely. When we revert the transaction with the Back button, they initialize properly and display normally during the popEnter animation.

在我简短的测试中,它得到了怪异 - 如果我设置的动画为孩子片段(见下文),在退出动画间歇运行时,我们添加片段 B

In my brief testing, it got weirder - if I set the animations for the child fragments (see below), the exit animation runs intermittently when we add fragment B

getChildFragmentManager()
  .beginTransaction()
  .setCustomAnimations(enter, exit)
  .replace(R.id.fragmentOneHolder, new FragmentA1())
  .replace(R.id.fragmentTwoHolder, new FragmentA2())
  .commit()

我想达到的效果很简单 - 我想要的退出(?还是应 popExit )动画的片段 A (anim2)运行,动态显示整个容器,包括其嵌套子。

The effect I want to achieve is simple - I want the exit (or should it be popExit?) animation on fragment A (anim2) to run, animating the whole container, including its nested children.

有没有什么办法来实现这一目标?

Is there any way to achieve that?

修改:请找一个测试用例这里

Edit: Please find a test case here

EDIT2 :感谢@StevenByle为推动我继续与静态动画尝试。显然,你可以在每个运算基础(而不是全球整个交易),这意味着孩子们能有一个不确定的静态动画组设置动画,而他们的父母可以有不同的动画,整个​​事情可以提交在一个事务中。请参见下面的讨论和更新测试用例项目

Edit2: Thanks to @StevenByle for pushing me to keep trying with the static animations. Apparently you can set animations on a per-op basis (not global to the whole transaction), which means the children can have an indefinite static animation set, while their parent can have a different animation and the whole thing can be committed in one transaction. See the discussion below and the updated test case project.

推荐答案

为了避免用户看到嵌套片段当父片段被除去/中可以模拟事务代替消失那些片段仍被present为他们提供的图像,因为它们出现在屏幕上。此图片将会被用作背景的嵌套片段容器,这样即使嵌套片段的意见消失的图像将模拟他们的presence。另外,我看不出有松动的嵌套片段的观点是一个问题的互动,因为我不认为你会希望用户采取行动他们时,他们只是在被删除(可能是因为用户操作的过程井)。

In order to avoid the user seeing the nested fragments disappearing when the parent fragment is removed/replaced in a transaction you could "simulate" those fragments still being present by providing an image of them, as they appeared on the screen. This image will be used as a background for the nested fragments container so even if the views of the nested fragment go away the image will simulate their presence. Also, I don't see loosing the interactivity with the nested fragment's views as a problem because I don't think you would want the user to act on them when they are just in the process of being removed(probably as a user action as well).

我做了一个小例子,并设置背景图片(基本的东西)。

I've made a little example with setting up the background image(something basic).

这篇关于在过渡动画嵌套片段消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆