popupWindow的使用和注意事项

来源:互联网 发布:网络棋牌怎么不违法 编辑:程序博客网 时间:2024/05/01 21:50

View popView = getLayoutInflater().inflate(R.layout.message3deletepop,

    null);

TextView deleTextView = (TextView) popView.findViewById(R.id.message3_delete_text);

popupWindow = new PopupWindow(popView,

    LinearLayout.LayoutParams.WRAP_CONTENT,

    LinearLayout.LayoutParams.WRAP_CONTENT);

popupWindow.setBackgroundDrawable(new PaintDrawable());

popupWindow.setFocusable(true);

popupWindow.setOutsideTouchable(true);

popupWindow.update();


显示方式3种


popupWindow.showAsDropDown(view);

popupWindow.showAsDropDown(viewxoffyoff);

popupWindow.showAtLocation(parentgravityxy);

至于作用相信大家都能通过方法名看得懂


另外:popupWindow.setBackgroundDrawable(new PaintDrawable());也可以自己设置一个透明色,这个是必须的,如果不加设置背景,则整个页面只有home键起作用,其他地方全都被屏蔽,无法点击


使用popupWindow.showAtLocation(parentgravityxy);的时候如果设置了Gravity.TOP的话,top是无视状态栏高度的,所以要获取状态栏高度statusBarHeight,使y = statusBarHeight

Rect frame = new Rect();

getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);

int statusBarHeight = frame.top;

状态栏高度获取要在布局完成之后,否则会是0


同时可以使用

setOnDismissListener来监听popupWindow的消失

0 0
原创粉丝点击