解决 Attempting to destroy the window while drawing!
2020-12-13 16:27
标签:des style blog http io color ar os sp 当对Dialog进行关闭时,如果有大量的操作,比如动画、绘图什么的,就可能出现这样的错误 Attempting to destroy the window while drawing! 比如,我在自定义的Dialog中的dismiss中进行了这样的操作,然后就报错了。其实可以忽略的,但毕竟不爽。 通过Google查到了解决办法。——通过handler来解决 参考网址:http://stackoverflow.com/questions/17923577/dialogfragment-animation-of-layout-and-attempting-to-destroy-the-window-while-d
You don‘t need the 10 ms delay. You can simply use the 后来,我在下发评论中发现了post可以直接解决,不用10mms的时间。于是就用了post。下面是最终解决问题后的代码: 解决 Attempting to destroy the window while drawing! 标签:des style blog http io color ar os sp 原文地址:http://www.cnblogs.com/tianzhijiexian/p/4083547.html @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);
}
@Override
public void onAnimationEnd(Animation animation) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
dismiss();
}
}, 10);
post()
method. @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!
文章链接:http://soscw.com/essay/36150.html