PopupWindow的使用
来源:互联网 发布:360防火墙软件 编辑:程序博客网 时间:2024/05/29 17:24
使用PopupWindow可实现弹出窗口效果
一、首先初始化一个PopupWindow,指定窗口大小参数。
PopupWindow mPop = new PopupWindow(getLayoutInflater().inflate(R.layout.window,null),
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
也可以分开写:
LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
//自定义布局
ViewGroup menuView = (ViewGroup) mLayoutInflater.inflate(
PopupWindow mPop = new PopupWindow(menuView, LayoutParams.WRAP_CONTENT,
当然也可以手动设置PopupWindow大小。
mPop.setContentView(menuView );//设置包含视图
mPop.setWidth(int )
mPop.setHeight(int )//设置弹出框大小
mPop.setOutsideTouchable(true);//这里设置显示PopuWindow之后在外面点击是否有效。如果为false的话,那么点击PopuWindow外面并不会关闭PopuWindow。当然这里很明显只能在Touchable下才能使用。
当有mPop.setFocusable(false);的时候,说明PopuWindow不能获得焦点,即使设置设置了背景不为空也不能点击外面消失,只能由dismiss()消失,但是外面的View的事件还是可以触发,back键也可以顺利dismiss掉。当设置为popuWindow.setFocusable(true);的时候,加上下面两行设置背景代码,点击外面和Back键才会消失。
mPop.setFocusable(true);需要顺利让PopUpWindow
mPop.setBackgroundDrawable(new ColorDrawable(0));
mPop.showAsDropDown(anchor, 0, 0);//设置显示PopupWindow的位置位于View的左下方,x,y表示坐标偏移量
mPop.showAtLocation(findViewById(R.id.parent),
0 0
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow的使用!!!
- 关于popupWindow的使用
- PopupWindow的使用
- PopupWindow的使用例子
- PopupWindow的使用
- popupWindow的使用心得
- PopupWindow的使用
- PopupWindow的使用
- Android PopupWindow的使用!!!
- PopupWindow的使用
- PopupWindow的使用
- popupWindow的使用
- PopupWindow的使用
- PopupWindow的使用
- Popupwindow的使用
- PopupWindow的使用
- ZOJ 3811——Untrusted Patrol
- 干货:中国移动互联网行业深度报告
- Http报文
- 获取windows8系统最高权限--system权限
- 第一篇博文
- PopupWindow的使用
- [HDU 5005 Compromise] 阅读理解+记忆化搜索
- 【OpenCV学习笔记】【函数学习】十三(剔除检测到的不符合要求的对象)
- ListView嵌套ListView的问题
- Spring整合JPA
- java中文件读写
- 【自考】数据库系统原理第二章
- How time flies----漫步
- 【FFT加速特征多项式解线性递推】hdu4914