动画上解雇的对话片段 [英] Animate a dialog fragment on dismiss

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

问题描述

我试图让dialogfragment关闭时的动画 - 我试图改写如下解雇,onDismiss,onCancel和方法的onDestroy,没有运气 - 有人可以点我在正确的方向。

  @覆盖
公共无效解雇(){
    如果(mDismissAnimationFinished){
        super.dismiss();
    }其他{        mShrink.setAnimationListener(新Animation.AnimationListener(){
            @覆盖
            公共无效onAnimationStart(动画动画){
            }            @覆盖
            公共无效onAnimationEnd(动画动画){
                mDismissAnimationFinished = TRUE;
                解雇();
            }            @覆盖
            公共无效onAnimationRepeat(动画动画){            }
        });
        mCurrentContainer.startAnimation(mShrink);
    }
}


解决方案

我只是做这与常规的对话框子类,我的解决方案应该转移到 DialogFragment 准确。

看起来你很接近,只是你应当在调用 super.dismiss()在onAnimationEnd(),而不是辞退( )。原因是,如果你调用辞退(),将递归调用你已经在功能!

编辑:

在外部类定义一个包装方法或YourDialogFragment.super()调用它。

 无效parentDismiss(){super.dismiss()}

和调用从 onAnimationEnd()

即使是这样,你仍然有竞争条件多了一个问题,当你取消对话框,它正被另一个线程驳回。为了解决这个问题,设置一个布尔值 mIsDismissed 第一次你onDismiss()被调用,这样如果之前另一再次调用在onStart()时(你将覆盖在onStart()翻转布尔背面)的 onDismiss()的不执行两次身体。

我在这里写了一个解决办法,不使用 DialogFragment ,只是一个普通的对话框。这是测试和工作,所以只是看我用的是逻辑和复制,或者如果你想使用它。

<一个href=\"https://github.com/tom-dignan/nifty/blob/master/src/com/tomdignan/nifty/dialogs/NiftyProgressDialog.java\" rel=\"nofollow\">https://github.com/tom-dignan/nifty/blob/master/src/com/tomdignan/nifty/dialogs/NiftyProgressDialog.java

I'm trying to get a dialogfragment to animate when closed - I've tried to overwrite the dismiss, onDismiss, onCancel and onDestroy methods as below, with no luck - can someone point me in the right direction?

@Override
public void dismiss() {
    if (mDismissAnimationFinished) {
        super.dismiss();
    } else {

        mShrink.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                mDismissAnimationFinished = true;
                dismiss();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        mCurrentContainer.startAnimation(mShrink);
    }
}

解决方案

I just did this with a regular dialog subclass and my solution should transfer over to DialogFragment exactly.

It looks like you're very close, just that you should be calling super.dismiss() in onAnimationEnd() rather than dismiss(). The reason is that if you call dismiss(), it will recursively call the function you are already in!

EDIT:

Define a wrapper method in the outer class or call it with YourDialogFragment.super().

void parentDismiss() { super.dismiss() }

and call that from your onAnimationEnd().

Even then, you'll still have one more problem with race conditions when you are cancelling the dialog and it is being dismissed by another thread. To solve this, set a boolean mIsDismissed the first time your onDismiss() is called so that if it is called again before another onStart() occurs (you will override onStart() to flip the boolean back) that onDismiss()'s body isn't executed twice.

I have written a solution here, which does not use DialogFragment, just a regular Dialog. It is tested and working, so just look at the logic I use and copy it, or if you want, use it.

https://github.com/tom-dignan/nifty/blob/master/src/com/tomdignan/nifty/dialogs/NiftyProgressDialog.java

这篇关于动画上解雇的对话片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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