原因:在View的onAttachedToWindow之前进行post,会失败
解决方法
private boolean mAttached;
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mAttached = true;
}
@Override
protected void onDetachedFromWindow() {
mAttached = false;
super.onDetachedFromWindow();
}
public void show() {
//....
if (mAttached) {
postDelayed(mDelayedShow, MIN_DELAY);
} else {
Handler handler = new Handler();
handler.post(mDelayedShow);
}
}
网友评论