Android实战简易教程-第七十二枪(PopupWindow浮动窗)

本文介绍了Android中的PopupWindow,它是一个浮动视图容器,显示在当前活动的上方。PopupWindow需要指定宽高和布局文件,并有两种弹出方式。文中通过实例展示了如何使用showAtLocation方法和showAsDropDown方法展示PopupWindow,还涉及了PopupWindow的动画设置和事件监听。
摘要由CSDN通过智能技术生成

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)

普通方法

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值