关于View.getHeight和getWidth为0的解决方案(待深入学习)
来源:互联网 发布:基于梯度的分水岭算法 编辑:程序博客网 时间:2024/06/07 21:52
项目中使用到了PopupWindow填充layout然后根据点击的View以及PopupWindow中View宽高在适配的位置显示PopuWindow的问题,
但是 inflate 后的View宽高一直是得到为0,很郁闷, 但是直接设置数值是肯定不行的
popwindow.showAtLocation();
最后网上查了下用以下方法解决了
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
//view为填充后得到的View实例
view.measure(w, h);
//popwindow为要显示的浮动窗口
popwindow = new PopupWindow(view,view.getMeasuredWidth()
,view.getMeasuredHeight(),true);
//之后再获得宽高就不为0了
popwindow.getWidth();
popwindow.getHeight();
关于MeasureSpec这个类不了解,感觉应该要深入研究下,为什么一开始得不到值设了之后就行了,但是项目太紧所以留以后再补上我的研究结果
0 0
- 关于View.getHeight和getWidth为0的解决方案(待深入学习)
- android view getWidth 和 getHeight 的值为0
- android view getWidth 和 getHeight 的值为0
- android view getWidth 和 getHeight 的值为0
- 为什么View中的getWidth()和getHeight()值为0
- 为何 view.getWidth和view.getHeight 的返回值为0
- View的getWidth,getHeight为0的解决方法
- 关于控件getWidth和getHeight方法都为0的解释及解决方法
- getWidth() getHeight() ,返回的值为0
- android view.getWidth(), view.getHeight() 返回0的问题的解决方案
- android view.getWidth(), view.getHeight() 返回0的问题的解决方案
- 关于View的getHeight()值为0
- Android : View.getWidth() 和 view.getHeight() 返回0
- android自定义View中getWidth和getHeight返回0
- 使用View的getWidth(),getHeight()方法返回0的问题
- android之view获取getWidth()和getHeight()
- android之view获取getWidth()和getHeight()
- TODO:view的getwidth(), getHeight()什么时候会有值
- C#之二十二 WIN应用程序的安装部署
- PHP学习
- 远程控制灯的程序解释
- poj-2955-Brackets
- redis-cli命令入门
- 关于View.getHeight和getWidth为0的解决方案(待深入学习)
- 面向对象的3个基本要素和5个基本设计原则
- 接口
- AngularJS学习记录-过滤器(排序方式过滤)
- HDU 2612 Find a way(两次BFS)
- 第十周项目—阅读程序,写出执行结果(1)
- IDEA+Maven+Spring+SpringMVC+SpringJDBC整合Demo
- NYOJ 题目860 又见01背包
- java classloader机制