Android PopupWindow用法(三) PopupWindow 的show方法

Section1

popupWindow.showAsDropDown(tv_bottom_b);
popupWindow.showAsDropDown(tv_bottom_b,100,100);
popupWindow.showAsDropDown(tv_bottom_b,100,100, Gravity.RIGHT|Gravity.TOP);
 
第一个方法  showAsDropDown 我们前面已经用过了,不做分析
第二个方法多了两个参数,分别代表x和y方向的偏移量,单位是px,也比较简单
第三个方法需要API 19 的支持,多了个Gravity参数,也比较简单,
 
我们着重分析第四个方法
 
Section2
/**
 * <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);
}

通过实验我们发现,当使用showAtLocation方法的时候,
第一个参数view就不再影响popup window的位置了
 
这个时候要靠 gravity以及x,y 来确定view的位置。
 
 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值