博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
显示popupWindow
阅读量:1980 次
发布时间:2019-04-27

本文共 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();

转载地址:http://vphpf.baihongyu.com/

你可能感兴趣的文章
行为树 BT
查看>>
Cassandra & CQL
查看>>
Oracle数据库
查看>>
Oracle数据库命令
查看>>
plsql
查看>>
有限状态机FSM
查看>>
Win10 Docker
查看>>
Python绘制动画并保存为gif/mp4 (matplotlib)
查看>>
PRM概率路线图
查看>>
ROS(六)——订阅者Subscriber的编程实现(C++ & Python)
查看>>
ROS(七)——话题消息的定义与使用
查看>>
yolov3入门实战
查看>>
B树 & B+树
查看>>
Node-Red(一)——简介与安装
查看>>
representation learning 表示学习/表征学习
查看>>
Haar特征
查看>>
Stereo Matching (双目)立体匹配 & 视差图 & 双目图片进行立体匹配获取深度图进行三维重建的步骤
查看>>
Python 之 histogram直方图
查看>>
Python 之 Scatter散点图
查看>>
Python实现决策树 Desision Tree & 可视化
查看>>