问题描述:想在跳转到Activity是就显示菜单,所以在onCreate()方法中让popUpWindow显示,抛出异常
原因:
showAtLocation(View parent, int gravity, int x, int y);
此时parent还没有初始化完成
解决方法,通过Handler发送延时消息,延时调用。
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
popupWindow.showAtLocation(findViewById(R.id.rlShowImage), Gravity.CENTER|Gravity.CENTER, 0, 0);
popupWindow.update();
break;
}
}
};
在onCreate()函数调用
handler.sendEmptyMessageDelayed(0, 100);
经测试,在onStart()方法中直接显示也会抛出此异常。
1万+

被折叠的 条评论
为什么被折叠?



