码迷,mamicode.com
首页 > Windows程序 > 详细

解决 Attempting to destroy the window while drawing!

时间:2014-11-08 16:44:46      阅读:1089      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   os   sp   

当对Dialog进行关闭时,如果有大量的操作,比如动画、绘图什么的,就可能出现这样的错误

 Attempting to destroy the window while drawing! 

比如,我在自定义的Dialog中的dismiss中进行了这样的操作,然后就报错了。其实可以忽略的,但毕竟不爽。

    @Override
    public void dismiss() {
        Animation anim = AnimationUtils.loadAnimation(context, R.anim.dialog_main_hide_amination);
        
        anim.setAnimationListener(new AnimationListener() {
            
            @Override
            public void onAnimationStart(Animation animation) {
            }
            
            @Override
            public void onAnimationRepeat(Animation animation) {
            }
            
            @Override
            public void onAnimationEnd(Animation animation) {
            
                        Dialog.super.dismiss();
                
            }
        });

        Animation backAnim = AnimationUtils.loadAnimation(context, R.anim.dialog_root_hide_amin);
        
        view.startAnimation(anim);
        backView.startAnimation(backAnim);
    }

 

通过Google查到了解决办法。——通过handler来解决

参考网址:http://stackoverflow.com/questions/17923577/dialogfragment-animation-of-layout-and-attempting-to-destroy-the-window-while-d

bubuko.com,布布扣

@Override
public void onAnimationEnd(Animation animation) {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            dismiss();
        }
    }, 10);

 

You don‘t need the 10 ms delay. You can simply use the post() method. 

后来,我在下发评论中发现了post可以直接解决,不用10mms的时间。于是就用了post。下面是最终解决问题后的代码:

    @Override
    public void dismiss() {
        Animation anim = AnimationUtils.loadAnimation(context, R.anim.dialog_main_hide_amination);
        
        anim.setAnimationListener(new AnimationListener() {
            
            @Override
            public void onAnimationStart(Animation animation) {
            }
            
            @Override
            public void onAnimationRepeat(Animation animation) {
            }
            
            @Override
            public void onAnimationEnd(Animation animation) {
                view.post(new Runnable() {
                    @Override
                    public void run() {
                        Dialog.super.dismiss();
                    }
                });
                
            }
        });
        Animation backAnim = AnimationUtils.loadAnimation(context, R.anim.dialog_root_hide_amin);
        
        view.startAnimation(anim);
        backView.startAnimation(backAnim);
    }

 

解决 Attempting to destroy the window while drawing!

标签:des   style   blog   http   io   color   ar   os   sp   

原文地址:http://www.cnblogs.com/tianzhijiexian/p/4083547.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!