Android PopupWindow用法(五) showAtLocation

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

好吧。。。

都不按坐标系来的。。。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值