PopupWindow可实现弹窗效果,但是,Popupwidow没有默认布局,需要我们自己设置。
一.PopupWindow的API
构造方法摘要
PopupWindow()
Create a new empty, non focusable popup window of dimension (0,0).
//创建一个空的、没有获取焦点的、长宽尺寸均为0的popup window
PopupWindow(Context context)
Create a new empty, non focusable popup window of dimension (0,0).
//创建一个空的、没有获取焦点的、长宽尺寸均为0的popup window
PopupWindow(Context context, AttributeSet attrs)
Create a new empty, non focusable popup window of dimension (0,0).
//创建一个空的、没有获取焦点的、长宽尺寸均为0的popup window
PopupWindow(Context context, AttributeSet attrs, int defStyle)
Create a new empty, non focusable popup window of dimension (0,0).
//创建一个空的、没有获取焦点的、长宽尺寸均为0的popup window
PopupWindow(int width, int height)
Create a new empty, non focusable popup window.
//创建一个没有获取焦点的、宽为width长为height的popup window
PopupWindow(View contentView)
Create a new non focusable popup window which can display the contentView.
//创建一个没有获取焦点的、显示contentView的popup window
PopupWindow(View contentView, int width, int height)
Create a new non focusable popup window which can display the contentView.
//创建一个没有获取焦点的、宽为width长为height显示contentView的popup window
PopupWindow(View contentView, int width, int height, boolean focusable)
Create a new popup window which can display the contentView.
//创建一个根据focusable来判断是否获取焦点的、宽为width长为height显示contentView的popup window
方法摘要
void dismiss()
Dispose of the popup window.
//使popup window消失
int getAnimationStyle()
Return the animation style to use the popup appears and disappears
//返回该popup window出现或消失的动画类型,返回值为整型
Drawable getBackground()
Return the drawable used as the popup window's background.
//返回popup window的背景,返回值为Drawable类型
View getContentView()
Return the view used as the content of the popup window.
//返回popup window展示的内容,返回值为一个View
int getHeight()
Return this popup's height MeasureSpec
//返回该popup window的高度值,返回值为int型
int getInputMethodMode()
Return the current value in setInputMethodMode(int).
//返回当前popup window对输入法的设置模式
int getMaxAvailableHeight(View anchor)
Returns the maximum height that is available for the popup to be completely shown.
//返回能使当前popup window完整显示的最大高度
int getMaxAvailableHeight(View anchor, int yOffset)
Returns the maximum height that is available for the popup to
一.PopupWindow的API
构造方法摘要
PopupWindow()
Create a new empty, non focusable popup window of dimension (0,0).
//创建一个空的、没有获取焦点的、长宽尺寸均为0的popup window
PopupWindow(Context context)
Create a new empty, non focusable popup window of dimension (0,0).
//创建一个空的、没有获取焦点的、长宽尺寸均为0的popup window
PopupWindow(Context context, AttributeSet attrs)
Create a new empty, non focusable popup window of dimension (0,0).
//创建一个空的、没有获取焦点的、长宽尺寸均为0的popup window
PopupWindow(Context context, AttributeSet attrs, int defStyle)
Create a new empty, non focusable popup window of dimension (0,0).
//创建一个空的、没有获取焦点的、长宽尺寸均为0的popup window
PopupWindow(int width, int height)
Create a new empty, non focusable popup window.
//创建一个没有获取焦点的、宽为width长为height的popup window
PopupWindow(View contentView)
Create a new non focusable popup window which can display the contentView.
//创建一个没有获取焦点的、显示contentView的popup window
PopupWindow(View contentView, int width, int height)
Create a new non focusable popup window which can display the contentView.
//创建一个没有获取焦点的、宽为width长为height显示contentView的popup window
PopupWindow(View contentView, int width, int height, boolean focusable)
Create a new popup window which can display the contentView.
//创建一个根据focusable来判断是否获取焦点的、宽为width长为height显示contentView的popup window
方法摘要
void dismiss()
Dispose of the popup window.
//使popup window消失
int getAnimationStyle()
Return the animation style to use the popup appears and disappears
//返回该popup window出现或消失的动画类型,返回值为整型
Drawable getBackground()
Return the drawable used as the popup window's background.
//返回popup window的背景,返回值为Drawable类型
View getContentView()
Return the view used as the content of the popup window.
//返回popup window展示的内容,返回值为一个View
int getHeight()
Return this popup's height MeasureSpec
//返回该popup window的高度值,返回值为int型
int getInputMethodMode()
Return the current value in setInputMethodMode(int).
//返回当前popup window对输入法的设置模式
int getMaxAvailableHeight(View anchor)
Returns the maximum height that is available for the popup to be completely shown.
//返回能使当前popup window完整显示的最大高度
int getMaxAvailableHeight(View anchor, int yOffset)
Returns the maximum height that is available for the popup to

本文详细介绍了PopupWindow的各种属性和用法,包括构造方法、API调用,如设置内容、宽高、焦点等。还展示了如何在指定位置显示PopupWindow,并给出了在控件下方以动画方式进出的示例代码。通过设置动画资源和style,实现了PopupWindow平滑的显示和消失效果。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



