1.参考文章
2.知识点
1.常用方法
- showAsDropDown
- showAtLocation
- 在屏幕居中显示PopWindow: popwindow.showAtLocation(1个View,Gravity.CENTER,0,0);
2.源码
- PopWindow默认位置就是在锚点View的下方,'左边'对齐锚点View,如果PopWindow的尺寸过大,则会进行偏移
android/widget/PopupWindow.java
private static final int DEFAULT_ANCHORED_GRAVITY = Gravity.TOP | Gravity.START;
public void showAsDropDown(View anchor) {
showAsDropDown(anchor, 0, 0);
}
public void showAsDropDown(View anchor, int xoff, int yoff) {
showAsDropDown(anchor, xoff, yoff, DEFAULT_ANCHORED_GRAVITY);
}
3.本地验证