码迷,mamicode.com
首页 > 移动开发 > 详细

Android PopupWindow显示在控件上方或者下方

时间:2015-01-23 16:29:07      阅读:430      评论:0      收藏:0      [点我收藏+]

标签:

项目中实现

Android PopupWindow显示在控件上方或者下方


主要代码如下  




View view = mInflater.inflate(R.layout.layout_popupwindow, null);
PopUpwindowLayout popUpwindowLayout = (PopUpwindowLayout) view.findViewById(R.id.llayout_popupwindow);
popUpwindowLayout.initViews(mContext, titles, false);
final PopupWindow popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
int popupWidth = view.getMeasuredWidth();
int popupHeight = view.getMeasuredHeight();
int[] location = new int[2];
// 允许点击外部消失
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
// 获得位置
v.getLocationOnScreen(location);
popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, (location[0] + v.getWidth() / 2) - popupWidth / 2, location[1] - popupHeight);

技术分享


附图片和Demo下载链接下载完成Demo点击打开链接

Android PopupWindow显示在控件上方或者下方

标签:

原文地址:http://blog.csdn.net/ronaldong99/article/details/43055849

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!