popupwindow 的 showAsDropDown 比较鸡肋
开发中用的比较多的是
showAtLocation
Section1 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) { showAtLocation(parent.getWindowToken(), gravity, x, y); }
Gravity 可选参数如下
/** Push object to the top of its container, not changing its size. */ public static final int TOP = (AXIS_PULL_BEFORE|AXIS_SPECIFIED)<<AXIS_Y_SHIFT; /** Push object to the bottom of its container, not changing its size. */ public static final int BOTTOM = (AXIS_PULL_AFTER|AXIS_SPECIFIED)<<AXIS_Y_SHIFT; /** Push object to the left of its container, not changing its size. */ public static final int LEFT = (AXIS_PULL_BEFORE|AXIS_SPECIFIED)<<AXIS_X_SHIFT; /** Push object to the right of its container, not changing its size. */ public static final int RIGHT = (AXIS_PULL_AFTER|AXIS_SPECIFIED)<<AXIS_X_SHIFT;除此之外还有其他参数。。暂不介绍======================================================================Section2 offset x ,offset y一开始以为 这里的x,y 应是都以左上角为0,0,向右,向下为正方向的,后来发现不对。。。坑。。。。。。public static class LayoutParams extends ViewGroup.LayoutParams implements Parcelable { /** * X position for this window. With the default gravity it is ignored. * When using {@link Gravity#LEFT} or {@link Gravity#START} or {@link Gravity#RIGHT} or * {@link Gravity#END} it provides an offset from the given edge. */ @ViewDebug.ExportedProperty public int x; /** * Y position for this window. With the default gravity it is ignored. * When using {@link Gravity#TOP} or {@link Gravity#BOTTOM} it provides * an offset from the given edge. */ @ViewDebug.ExportedProperty public int y;
原来这里是an offset from the given edge
好吧。。。
都不按坐标系来的。。。