PopupWindow的使用
来源:互联网 发布:tcp拥塞控制算法 编辑:程序博客网 时间:2024/06/06 04:35
PopupWindow,其实就是一个弹出框,它和我们之前学过的Dialog对话框有很多相似的地方,几乎都是在后台用代码创建,不能在布局文件中创建。
与Dialog的区别:
最近关键的区别在于Dialog不能指定显示位置,只能默认显示在屏幕的最中间。而PopuoWindow是可以指定显示位置的,随便哪个位置都可以,比较灵活。
PopWindow的构造函数:
1. //方法一:
2. public PopupWindow (Context context)
3. //方法二:
4. public PopupWindow(View contentView)
5. //方法三:
6. public PopupWindow(View contentView, int width, int height)
7. //方法四:
8. public PopupWindow(View contentView, int width, int height, boolean focusable)
以上4个其实采用哪个构造函数都可以,但是有3个属性是PopupWindow必须设置的:
1. ViewcontentView
2. Intwidth
3. Intheight
contentView必须设置因为PopupWindow不像Dialog那样有默认布局。它必须自己定义布局。
Width和height是设置显示PopupWindow的宽高尺寸。
显示函数:
主要有3个:
//相对某个控件的位置(正左下方),无偏移
showAsDropDown(View anchor):
showAsDropDown(View anchor, int xoff, int yoff):
showAtLocation(View parent, int gravity, int x, int y):
前两个为先是在某个控件的下方,x和y为偏移量。
ShowAtLocation是显示在父控件的某个位置。
自己做了实验,上代码:
首先设置自定义的布局文件,代码比较简单,就不帖出来了,这是效果图:
设置PopupWindow以及显示的方法:
首先用LayoutInflater得到了自定义的view,然后设置了宽高属性,
然后重写了onKeyDown方法,
当用户按下Menu菜单时,显示窗口,当用户按下后退键,窗口消失。
一个简单的PopupWindow就创建完成了
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow的使用!!!
- 关于popupWindow的使用
- PopupWindow的使用
- PopupWindow的使用例子
- PopupWindow的使用
- popupWindow的使用心得
- PopupWindow的使用
- PopupWindow的使用
- Android PopupWindow的使用!!!
- PopupWindow的使用
- PopupWindow的使用
- popupWindow的使用
- PopupWindow的使用
- PopupWindow的使用
- Popupwindow的使用
- PopupWindow的使用
- zhu的Oracle数据库笔记
- 05-树7 堆中的路径 (25分)
- Python中常用的一些模块
- mybatis的缓存机制
- poj1952(经典dp题)
- PopupWindow的使用
- Git上传文件到远程仓库||更改远程仓库目录下的内容
- 2017山东省大学生程序设计竞赛(青岛科技大学)引发的感想
- JavaEE学习03--Servlet
- HDU 6023 Automatic Judge
- c++11 生产者和消费者模型
- 【优化】关于FOR ALL ENTRIES的小结
- http常用相应状态码
- 简单接口和继承的应用