PopupWindow显示在某个控件上方
来源:互联网 发布:js 读取cookie 编辑:程序博客网 时间:2024/05/16 13:02
一、自定义PopupWindow
public class PopupWindowView extends PopupWindow{ private int popupWidth; private int popupHeight; private ListView listView; private View parentView; public PopupWindowView(Context context , ArrayList<PopBean> popBeans ) { super(context); initView(context); setPopConfig(); initData(context,popBeans); } /** * 初始化控件 * <h3>Version</h3> 1.0 * <h3>CreateTime</h3> 2016/6/29,22:00 * <h3>UpdateTime</h3> 2016/6/29,22:00 * <h3>CreateAuthor</h3> vera * <h3>UpdateAuthor</h3> * <h3>UpdateInfo</h3> (此处输入修改内容,若无修改可不写.) * @param context */ private void initView(Context context) { parentView = View.inflate(context, R.layout.layout_popup_window, null); listView = (ListView) parentView.findViewById(R.id.popup_window_list); setContentView(parentView); } /** * 初始化数据 * <h3>Version</h3> 1.0 * <h3>CreateTime</h3> 2016/6/29,22:03 * <h3>UpdateTime</h3> 2016/6/29,22:03 * <h3>CreateAuthor</h3> vera * <h3>UpdateAuthor</h3> * <h3>UpdateInfo</h3> (此处输入修改内容,若无修改可不写.) * @param context * @param popBeans */ private void initData(Context context, ArrayList<PopBean> popBeans) { //给ListView添加数据 PopListViewAdapter popListViewAdapter = new PopListViewAdapter(context,popBeans); listView.setAdapter(popListViewAdapter); } /** * * 配置弹出框属性 * @version 1.0 * * @createTime 2015/12/1,12:45 * @updateTime 2015/12/1,12:45 * @createAuthor * @updateAuthor * @updateInfo (此处输入修改内容,若无修改可不写.) * */ private void setPopConfig() {// this.setContentView(mDataView);//设置要显示的视图 this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); // 设置弹出窗体可点击 this.setFocusable(true); ColorDrawable dw = new ColorDrawable(0xcc000000); this.setBackgroundDrawable(dw); this.setOutsideTouchable(true);// 设置外部触摸会关闭窗口 //获取自身的长宽高 parentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); popupHeight = parentView.getMeasuredHeight(); popupWidth = parentView.getMeasuredWidth(); } public ListView getListView() { return listView; } /** * 设置显示在v上方(以v的左边距为开始位置) * @param v */ public void showUp(View v) { //获取需要在其上方显示的控件的位置信息 int[] location = new int[2]; v.getLocationOnScreen(location); //在控件上方显示 showAtLocation(v, Gravity.NO_GRAVITY, (location[0]) - popupWidth / 2, location[1] - popupHeight); } /** * 设置显示在v上方(以v的中心位置为开始位置) * @param v */ public void showUp2(View v) { //获取需要在其上方显示的控件的位置信息 int[] location = new int[2]; v.getLocationOnScreen(location); //在控件上方显示 showAtLocation(v, Gravity.NO_GRAVITY, (location[0] + v.getWidth() / 2) - popupWidth / 2, location[1] - popupHeight); }}
二、布局<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <ListView android:id="@+id/popup_window_list" android:layout_width="match_parent" android:layout_height="wrap_content"> </ListView></LinearLayout>
阅读全文
0 0
- PopupWindow显示在某个控件上方
- PopupWindow显示在某个控件上方
- PopupWindow显示在某个控件上方
- Android PopupWindow显示在控件上方或者下方(demo)
- Android PopupWindow显示在控件上方或者下方
- popupwindow里含有listview,显示在控件上方
- Android自定义PopupWindow显示在控件上方或者下方
- Android自定义PopupWindow显示在控件上方或者下方
- Android自定义PopupWindow显示在控件上方或者下方
- 控件显示在原有控件上方 c#
- Android textView复制,popupwindow显示在文字上方
- popwindow 显示在某一控件的上方
- android popupwindow 弹出窗口在控件上方居中,比控件大一倍
- MFC/VC 鼠标悬停在控件上方显示信息
- 【android】让popupwindow显示在view的上方并与该view水平居中对齐
- 【android】让popupwindow显示在view的上方并与该view水平居中对齐
- 让popupwindow显示在view的上方并与该view水平居中对齐
- 让popupwindow显示在view的上方并与该view水平居中对齐
- VS2017 Xamarin扫描二维码并跳转网页
- 题目51:管闲事的小明
- 设计模式之模版方法
- 總結——關於2017 10 20測試的分析總結
- ajax httprequest 详解
- PopupWindow显示在某个控件上方
- HDU5976(找规律+费马小定理求逆元)
- 面向对象机制之抽象类和接口联系与区别
- 机器学习最好的科普文章
- nginx使用笔记
- TX1安装usbserial及cp210x驱动
- 手把手教学APK反编译实现源码阅读
- Unity实现拖拽功能
- ASP.NET没有魔法——ASP.NET MVC IoC