一个全屏PopupWindow的小问题
2016-07-04 10:01
465 查看
之前需要做一个全屏控件,大致是微信输入密码的那个dialog的样子~中间一个框是文本,下面靠底的一个自定义键盘。
选择了PopupWindow。
构造函数里
然后
view 是自己写的顶部title
后来发现这个PopupWindow会超出底部屏幕,超出部分大概就是状态拦➕标题栏的高度。于是一翻折腾
其中 setLayoutPraram 这个里方法不能在activity的oncreate里面调用,调试会发现获取的几个高度都是 0。
所以我放到了show里边,每次弹出调用一次,有点不好,但是实现了就没纠结了
选择了PopupWindow。
public class MyPopupWindow extends PopupWindow
构造函数里
View view = View.inflate(activity,R.layout.dialog_wheel_select,null); setContentView(view); this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT); ColorDrawable dw = new ColorDrawable(0x90000000); this.setBackgroundDrawable(dw);
然后
showAsDropDown(view);
view 是自己写的顶部title
后来发现这个PopupWindow会超出底部屏幕,超出部分大概就是状态拦➕标题栏的高度。于是一翻折腾
private void setLayoutPraram(BaseActivity activity){ DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); //状态栏 int statusBarHeight = frame.top; //自定义标题栏高度 int toolbarHeight = activity.getToolBar().getView().getHeight(); //屏幕高度 int mheight = metrics.heightPixels; this.setHeight(mheight - toolbarHeight - statusBarHeight); } public void show(View view,BaseActivity activity){ setLayoutPraram(activity); super.showAsDropDown(view); }
其中 setLayoutPraram 这个里方法不能在activity的oncreate里面调用,调试会发现获取的几个高度都是 0。
所以我放到了show里边,每次弹出调用一次,有点不好,但是实现了就没纠结了
相关文章推荐
- 在Linux环境中使用Ext3文件系统
- Nginx配置文件解析详解
- centos 7 minimal 安装vmtool
- nginx之location基础配置及location最佳实践
- 使用opencv249设置摄像头分辨率
- 每天学习一算法系列(3)--设计包含min函数的栈,要求函数min、push以及pop的时间复杂度都是O(1))
- Nginx+Tomcat7+Mencached负载均衡集群部署笔记
- “org/apache/commons/logging/LogFactory”错误的解决方式
- 最前端nginx.conf配置
- filezilla Can't open data connection.
- 解决8080端口被占用问题
- 通过smack client + openfire server 实现 peer to peer communication
- Linux学习(6)之安装Jenkins
- 一款不错的html5网站模板案例代码下载,用于开发个人网站,兼容手机与PC
- linux下给网卡加VLAN标签和私网地址
- Linux学习(5)之安装Tomcat
- 关于<context:property-placeholder>的一个有趣现象
- Asp.Net Core 发布和部署( MacOS + Linux + Nginx )
- 10个有用的Linux命令面试问题及答案
- linux命令 rm