PopupWindow

 1     /**
 2      * 显示一个PopupWindow
 3      *
 4      * @param v
 5      */
 6     private void show(View v) {
 7         PopupWindow mPopupWindow;
 8         LinearLayout mLayoutPopupWindow;
 9         //window的布局文件
10         mLayoutPopupWindow = (LinearLayout) getLayoutInflater().inflate(R.layout.popup_window, null);
11         mPopupWindow = new PopupWindow(mLayoutPopupWindow, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
12         mPopupWindow.setFocusable(true);
13         //点击PopupWindow以外的的区域,window消失
14         mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
15         mPopupWindow.setOutsideTouchable(true);
16         //计算显示位置   这里显示在v的正下方
17         int[] locations = new int[2];
18         v.getLocationOnScreen(locations);
19         Rect mRect = new Rect(locations[0], locations[1], locations[0] + v.getWidth(), locations[1] + v.getHeight());
20         int screenWidth = getResources().getDisplayMetrics().widthPixels;
21         mPopupWindow.showAtLocation(v, Gravity.NO_GRAVITY, (screenWidth - getResources().getDimensionPixelSize(R.dimen.popup_window_width)) / 2, mRect.bottom - getResources().getDimensionPixelSize(R.dimen.popup_window_margin_top));
22     }

 

转载于:https://www.cnblogs.com/hsji/p/5194357.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值