显示popupWindow
发布日期:2021-06-30 18:38:15
浏览次数:2
分类:技术文章
本文共 1547 字,大约阅读时间需要 5 分钟。
/** * ivOption点击后显示popupWindow * * @param ivOption */protected void showPopupWindow(View ivOption) { View itemView = (View) ivOption.getParent();// 得到ivOption的父控件 if (mIvOptionPopupWindow == null) { View contentView = View.inflate(this, R.layout.file_item_pop, null); int width = ViewGroup.LayoutParams.MATCH_PARENT; int height = itemView.getHeight(); mIvOptionPopupWindow = new PopupWindow(contentView, width, height, true); } // 点击popupwindow范围以外的地方时隐藏 mIvOptionPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mIvOptionPopupWindow.setOutsideTouchable(true); // 控制它放置的位置 if (isShowBottom(itemView)) {// 显示popupwindow在itemView的下方,偏移量都为0 mIvOptionPopupWindow.showAsDropDown(itemView, 0, 0); } else {// 显示popupwindow在itemView的上方,偏移量y都为-2*itemView.getHeight() mIvOptionPopupWindow.showAsDropDown(itemView, 0, -2 * itemView.getHeight()); }}/** * 判断popupWindow是否显示在条目的下方 * * @param itemView * @return */private boolean isShowBottom(View itemView) { // 得到屏幕的高度 // int heightPixels = // getResources().getDisplayMetrics().heightPixels;//方式1 int screenHeight = getWindowManager().getDefaultDisplay().getHeight();// 方式2 int[] location = new int[2]; // location[0]-->x // location[1]-->y itemView.getLocationInWindow(location); // 得到itemView在屏幕中Y轴的值 int itemViewY = location[1]; // 得到itemView距离屏幕底部的距离 int distance = screenHeight - itemViewY - itemView.getHeight(); if (distance < itemView.getHeight()) {// 条目下方放不下popupWindow return false; } else {// 条目下方放得下popupWindow return true; }}//让popupWindow消失mIvOptionPopupWindow.dismiss();
转载地址:https://linqiarui.blog.csdn.net/article/details/50764573 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年05月02日 04时25分56秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
leetcode46 全排列
2019-04-30
leetcode121 买卖股票的最佳时机
2019-04-30
leetcode 122 买卖股票的最佳时机II
2019-04-30
leetcode 309 最佳买卖股票含冷冻期
2019-04-30
leetcode 714 买卖股票的最佳时机含手续费
2019-04-30
leetcode3 无重复字符的最长子串
2019-04-30
leetcode 76 最小覆盖子串
2019-04-30
leetcode 1143. 最长公共子序列
2019-04-30
leetcode 83. 删除排序链表中的重复元素
2019-04-30
智能体 Intelligent Agent
2019-04-30
Network Compression网络压缩(一)
2019-04-30
GAN系列(零)—— GAN的发展(两条路线)
2019-04-30
Conditional GAN (CGAN) 条件生成网络
2019-04-30
强化学习(三) —— Policy Gradient 策略梯度
2019-04-30
docker安装oracle(win10)
2019-04-30
Cloudera Quickstart & HUE
2019-04-30
HUE
2019-04-30
CDH
2019-04-30
行为树 BT
2019-04-30
Cassandra & CQL
2019-04-30