popupWindow 用法总结 控制位置
Activity
}
Activity2
}
工具类
}
常用API
构造方法
- public PopupWindow(View contentView)
- public PopupWindow(Context context)
- public PopupWindow(View contentView, int width, int height)
- public PopupWindow(View contentView, int width, int height, boolean focusable)

- contentView为要显示的view;PopupWindow没有默认布局,它不会像AlertDialog那样只setTitle就能弹出来一个框,所以contentView必须设置。
- width和height为要显示的view的宽和高,值为像素值或MATCHT_PARENT、WRAP_CONTENT;如果View是从xml得到的,那么xml的第一层view的大小属性将被忽略;必须设置宽和高,否则显示不出来。
- focusable为是否能获得焦点
show方法
- showAsDropDown(View anchor) 相对某个控件的位置(正左下方),无偏移。最终调用的是下面的方法
- showAsDropDown(View anchor, int xoff, int yoff) 相对某个控件的位置,有偏移,xoff表示x轴的偏移,正值表示向左,负值表示向右;yoff表示相对y轴的偏移,正值是向下,负值是向上;最终调用的是下面的方法
- showAsDropDown(View anchor, int xoff, int yoff, int gravity) 【注:这个方法貌似不起作用】相对某个控件的某个位置,有偏移。gravity的默认值为DEFAULT_ANCHORED_GRAVITY= Gravity.TOP | Gravity.START
- showAtLocation(View parent, int gravity, int x, int y) 相对于父控件(不管view设置的是哪一个,参照物都是整个屏幕的根布局)的某个位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以设置偏移或无偏移。

/*** Displays the content view in a popup window anchored to the corner of* another view. The window is positioned according to the specified* gravity and offset by the specified x and y coordinates.* <p>* If there is not enough room on screen to show the popup in its entirety,* this method tries to find a parent scroll view to scroll. If no parent* view can be scrolled, the specified vertical gravity will be ignored and* the popup will anchor itself such that it is visible.* <p>* If the view later scrolls to move <code>anchor</code> to a different* location, the popup will be moved correspondingly.** @param anchor the view on which to pin the popup window* @param xoff A horizontal offset from the anchor in pixels* @param yoff A vertical offset from the anchor in pixels* @param gravity Alignment of the popup relative to the anchor** @see #dismiss()*/public void showAsDropDown(View anchor, int xoff, int yoff, int gravity)/*** <p>* Display the content view in a popup window at the specified location. If the popup window* cannot fit on screen, it will be clipped. See {@link android.view.WindowManager.LayoutParams}* for more information on how gravity and the x and y parameters are related. Specifying* a gravity of {@link android.view.Gravity#NO_GRAVITY} is similar to specifying* <code>Gravity.LEFT | Gravity.TOP</code>.* </p>** @param parent a parent view to get the {@link android.view.View#getWindowToken()} token from* @param gravity the gravity which controls the placement of the popup window* @param x the popup's x location offset* @param y the popup's y location offset*/public void showAtLocation(View parent, int gravity, int x, int y)
setFocusable
/*** <p>Changes the focusability of the popup window. When focusable, the* window will grab the focus from the current focused widget if the popup* contains a focusable {@link android.view.View}. By default a popup* window is not focusable.</p>** <p>If the popup is showing, calling this method will take effect only* the next time the popup is shown or through a manual call to one of* the {@link #update()} methods.</p>** @param focusable true if the popup should grab focus, false otherwise.** @see #isFocusable()* @see #isShowing()* @see #update()*/public void setFocusable(boolean focusable) {mFocusable = focusable;}
setOutsideTouchable
/*** <p>Controls whether the pop-up will be informed of touch events outside* of its window. This only makes sense for pop-ups that are touchable* but not focusable, which means touches outside of the window will* be delivered to the window behind. The default is false.</p>** <p>If the popup is showing, calling this method will take effect only* the next time the popup is shown or through a manual call to one of* the {@link #update()} methods.</p>** @param touchable true if the popup should receive outside* touch events, false otherwise** @see #isOutsideTouchable()* @see #isShowing()* @see #update()*/public void setOutsideTouchable(boolean touchable) {mOutsideTouchable = touchable;}
附件列表
popupWindow 用法总结 控制位置的更多相关文章
- Android popupwindow 弹出的位置问题
在Android开发中,需要用到PopupWindow这个类.在初始化完成,显示之前,都需要获得这个对象的width,height去计算popupWindow弹出的位置. 这个时候会发现取得的widt ...
- Android中PopupWindow用法
参考资料链接:http://developer.android.com/reference/android/widget/PopupWindow.html 在Android中有很多级别的Window, ...
- Android PopupWindow怎么合理控制弹出位置(showAtLocation)
说到PopupWindow,应该都会有种熟悉的感觉,使用起来也很简单 // 一个自定义的布局,作为显示的内容 Context context = null; // 真实环境中要赋值 int layou ...
- 屏幕旋转时调用PopupWindow update方法更新位置失效的问题及解决方案
接到一个博友的反馈,在屏幕旋转时调用PopupWindow的update方法失效.使用场景如下:在一个Activity中监听屏幕旋转事件,在Activity主布局文件中有个按钮点击弹出一个Pop ...
- PopupWindow计算弹出位置
1.首先自定义PopupWindow popWindowView= LinearLayout.inflate(context, R.layout.popupWindow,null); po ...
- opencv播放视屏并控制位置
原文地址:http://blog.csdn.net/augusdi/article/details/9000592 cvGetCaptureProperty是我们需要使用到的获取视频属性的函数. do ...
- 一些特殊ACII码的用法 在控制台中覆盖显示、刷新显示和删除字符
很好奇怎么实现在控制台中不换行直接显示新的信息把旧的替换掉,于是找到了两个ACII码字符,他们可以帮助实现. 一个是‘\b’字符,这个字符是backspace,即删除上一个字符,于是可以清除以显示的旧 ...
- Unity 3D 中实现对物体 位置(position) 旋转(rotation) 大小(scale) 的全面控制
今天分享一些基础控制的脚本 1.位置(Position): 控制位置很简单,首先要知道要在xyz哪几个轴上移动,确定好后定义代表着那些轴的移动变量,速度(m_speed在函数外定义为全局变量)然后通过 ...
- android PopupWindow显示位置
PopupWindow的显示及位置设置 window.showAtLocation(parent, Gravity.RIGHT | Gravity.BOTTOM, 10,10); 第一个参数指定Pop ...
随机推荐
- Web(click and script) 与 Web(HTTP/HTML)协议区别
Web(click and script) 与 Web(HTTP/HTML)协议区别 webjavascriptvbscript浏览器脚本login 先从最简单的说明上来看, Web(HTTP/HTM ...
- 图片热点的使用,html <area> 的用法
<area>标记主要用于图像地图,通过该标记可以在图像地图中设定作用区域(又称为热点),这样当用户的鼠标移到指定的作用区域点击时,会自动链接到预先设定好的页面.其基本语法结构如下: < ...
- Django+Nginx+uwsgi搭建自己的博客(二)
在上一篇博客中,为大家介绍了Django的一些基本概念以及建立了第一个App——Users,并且在数据库中建立了对应的表. 在这篇博客中,将为大家继续介绍数据库模型的定义和相关操作,以及Users A ...
- ref和out的用法和区别。
关于ref和out的用法和区别在网上已经有很多的解释,这里只不过是写下对于我而说比较容易理解的解释. ref和out都可以用来在函数中返回数据,类似于c++中指针. 参数 Ref Out 是否一定需要 ...
- Scrapy基础------css选择器基础
基本语法: * 选择所有节点 #container 选择id为container的节点 .container 选择所有class包含container的节点 li a 选取所有li 下所有a节点 ul ...
- [Usaco2015 Feb]Censoring --- AC自动机 + 栈
bzoj 3940 Censoring 题目描述 FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S. 他有一个包含n个单词的列表,列表里的n个单词记为T1......Tn. ...
- 【20181024T2】小C的序列【GCD性质+链表】
题面 [错解] 一眼不可做啊 哎分治? 算不了啊 真的是,打暴力走人 20pts (事实上,还有20pts是随机数据,加个小小的特判就可以) [正解] 首先,从l开始往后gcd最多只有O(log)种取 ...
- python开发_os.path
在python中,os.path模块在处理路径的时候非常有用 下面是我做的demo 运行效果: ========================================= 代码部分: ==== ...
- 读书笔记_Effective_C++_条款二十六:尽可能延后变量定义式的出现时间
这个条款从字面意思还是很好理解的,就是在使用这个变量前才去定义,而不是很早就定义了它,而在很后面的时候才去使用.这个条款只适用于对变量声明位置没有要求的语言,比如C++.对于像C或者一些脚本语言,语法 ...
- Android EditText 限制输入为ip类型
editText.setInputType(InputType.TYPE_CLASS_NUMBER); String digits = "0123456789."; editTex ...