PopupWindow--点击ListView的Item,popupwindow出现在点击item下方
来源:互联网 发布:pdf阅读软件 知乎 编辑:程序博客网 时间:2024/05/16 01:45
1.原理
ListView的 public void onItemClick(AdapterView<?> adapterView, View view, int position, long l)的view是所点击的Item的对应View,通过popupwindow.showAsDropDown(anchor);通过anchor的位置显示popupwindow
代码如下
<pre name="code" class="java">/** * show the reason why don't supply the dish by floatview * * @param anchor * @param item * @param curViewY */ private void showReason(View anchor, ConsignorDataRangeTimeItem item, int curViewY) { PopupView popup = new PopupView(this); View view = View.inflate(this, R.layout.consignor_reason_notsupply, null); popup.initView(this, view, popup.screenWidth / 2, WindowManager.LayoutParams.WRAP_CONTENT); if(popup.needReverse(anchor,curViewY)){ view.setBackgroundResource(R.drawable.popup_view_bg_reverse); } popup.showView(anchor, 0, 0); } @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { int id = adapterView.getId(); switch (id) { case R.id.consignor_data_range_list: ConsignorDataRangeTimeItem item = list.get(position); if (item.getNotCount() == 0) return; View anchor = view.findViewById(R.id.consignor_data_time_range__item_dropdown); int[]scr=new int[2]; view.getLocationOnScreen(scr);//获取view的绝对位置 showReason(anchor, item, scr[1]); } } public static class PopupView { private final Context mContext; private PopupWindow mPopup; private WindowManager wm; public int screenWidth; public int screenHeight; public PopupView(Context context) { mContext = context; } /** * reset the popupwindow */ public void reset() { mPopup.dismiss(); mPopup = null; } public void setScreen() { wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); //设置LayoutParams(全局变量)相关参数 WindowManager.LayoutParams params = new WindowManager.LayoutParams(); //获取屏幕尺寸 //Display display=wm.getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels; screenHeight = dm.heightPixels; } /** * init the popupview * * @param context * @param view the view add to popup view */ protected void initView(Context context, View view, int width, int height) { // TODO Auto-generated method stub if (width == 0 || height == 0) { setScreen(); width = screenWidth / 2; height = WindowManager.LayoutParams.WRAP_CONTENT; } mPopup = new PopupWindow(view, width, height); /*设置背景显示 */ //menuView.setBackgroundResource(R.color.transparent); //设置触摸外面时消失 mPopup.setOutsideTouchable(true); //设置系统动画 mPopup.setAnimationStyle(android.R.style.Animation_Dialog); mPopup.setTouchable(true); mPopup.setBackgroundDrawable(new BitmapDrawable()); mPopup.update(); //设置了可获得焦点才能让Popu盘Window中的控件获取相应 mPopup.setFocusable(true); } /** * show popup view * * @param anchor a parent view to get the getWindowToken() token from * @param offsetX * @param offsetY */ public void showView(View anchor, int offsetX, int offsetY) { // TODO Auto-generated method stub mPopup.showAsDropDown(anchor); //mPopup.showAtLocation(anchor, Gravity.RIGHT|Gravity.TOP, offsetX, offsetY); } /** * hide the popup view */ public void hideView() { if (mPopup.isShowing()) mPopup.dismiss(); } /** * * @param anchor * @param curViewY * @return if curViewY>=maxHeight return true; */ public boolean needReverse(View anchor, int curViewY) { int maxHeight= mPopup.getMaxAvailableHeight(anchor); return curViewY>=maxHeight; } }
0 1
- PopupWindow--点击ListView的Item,popupwindow出现在点击item下方
- PopupWindow+ListView item 点击无效解决办法
- popupwindow中ListView item点击事件无效的解决方案
- recyclerview点击item弹出popupwindow
- 关于Android中popupwindow的listview的item点击事件无效的解决方案
- listview点击item,在item的上边弹出popwindow
- ListView点击item底部弹出popupWindow删除、修改、取消选择框
- PopupWindow响应ListView Item事件
- ListView的Item点击效果
- ListView 的 item 点击效果
- ListView的item点击事件
- 获取ListView点击的Item
- ListView的item点击问题
- ListView item点击事件问题:第一次点击有效,再次点击item无效。场景是在item的展开效果
- listview中点击item出现选择框
- ListView的ITEM点击出现白色背景的解决方法
- listView点击空间的时候弹出 PopupWindow
- PopupWindow中ListView无法点击的问题
- PyQt4 实例源码阅读
- libc、glibc与gcc
- Appium logo 移动应用自动化测试 Appium
- des加密中c的算法和java算法一致的实现
- ArcGIS教程:什么是网络数据集?
- PopupWindow--点击ListView的Item,popupwindow出现在点击item下方
- Android布局常用控件
- getRunningTasks
- Fedora 20 安装试用体验全程讲解
- 乘法竖式(abc*de)
- 最长公共子序列和最长公共子串
- svn: E200007: Retrieval of mergeinfo unsupported解决
- FREERPD android客户端编译
- c语言编程---指针、引用