【问题标题】:Custom animation not called when using remove vs hide使用删除与隐藏时未调用自定义动画
【发布时间】:2014-11-10 18:16:11
【问题描述】:

我有一个片段,我想在打开时向左滑动,在关闭时向右滑动。显示部分工作正常,但是当我们关闭它时,如果我使用 hide(),它可以工作,但我想删除片段,以便它不会在配置更改等时显示,但是当 remove() 时,用于隐藏的相同动画不起作用叫做。请参阅下面的代码。

此代码有效,意味着它显示面板转到正确的动画

Fragment fragment = getFragmentManager().findFragmentByTag(Tags.PANEL_FRAGMENT_TAG.name());
        if (fragment != null) {
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.setCustomAnimations(R.animator.slide_in_right, R.animator.slide_out_right);
            transaction.hide(fragment);
            transaction.commit();
        }

此代码不起作用..任何指针?如何删除片段和动画仍然有效..

 Fragment fragment = getFragmentManager().findFragmentByTag(Tags.PANEL_FRAGMENT_TAG.name());
            if (fragment != null) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.animator.slide_in_right, R.animator.slide_out_right);
                **transaction.remove(fragment);**
                transaction.commit();
            }

【问题讨论】:

标签: android animation android-fragments android-animation


【解决方案1】:

我在 stackoverflow 的另一篇文章中找到了原因,这很有意义

这是原帖 How to animate fragment removal

推理:

"退出视图在进入视图的画布上动画,所以如果 没有进入画布没有动画画布。

为了显示动画,我必须始终使用替换和输入 与那些退出的碎片大小相同。动画完成后 完成后我将新片段的视图设置为消失。”

【讨论】:

  • 应该刚刚结束你的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-05
相关资源
最近更新 更多