PopupWindow的官方定义如下:
A popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.
也就是说它是一个浮动在当前界面上方并且可以显示在任意位置的View,前面的章节我们学习了弹出框,各式各样的,那么PopupWindow应该有两点和弹出框不同,一是PopupWindow必须指定宽高属性,而弹出框则不是必须指定;二是PopupWindow必须指定其布局文件。下面总结一下常用方法:
方法 |
类型 |
说明 |
PopupWindow(Context context) |
构造方法 |
Context为上下文对象 |
PopupWindow(int width, int height) |
构造方法 |
传入宽高属性 |
PopupWindow(View contentView, int width, int height) |
构造方法 |
传入布局文件及宽高属性 |
PopupWindow(View contentView, int width, int height, boolean focusable) |
构造方法 |
传入布局文件、宽高属性和是否获得焦点 |
dismiss() |
普通方法 |
隐藏PopupWindow |
setAnimationStyle(int animationStyle) |
普通方法 |