zoukankan      html  css  js  c++  java
  • 解决 Attempting to destroy the window while drawing!

    当对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

    @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);
        }
  • 相关阅读:
    ASP标准控件的重要性
    jndi的疑惑 转
    jms中topic和queue的区别
    JNDI解析
    javascript document 对象属性(转)
    SAX解析xml全解
    java路径解析
    深度学习之美(张玉宏)——第三章 机器学习三重门
    centos7 源码编译安装 php
    centos7 源码编译安装 nginx
  • 原文地址:https://www.cnblogs.com/tianzhijiexian/p/4083547.html
Copyright © 2011-2022 走看看