我是靠谱客的博主 魁梧海燕,这篇文章主要介绍关于PopupWindow wrap_content 后获取高度宽度,现在分享给大家,希望可以做个参考。

PopupWindow在创建时宽度高度设置为match_parent或者wrap_content时,通过getWidth、getHeight或者getContentView.getMeasuredWidth、getContentView.getMeasuredHeight 不能获取到真实的高度!

正确的方法获取高度的方法是创建之后调用measure方法对View进行测量,然后获取宽度与高度!

示例:

复制代码
1
2
3
4
5
6
View popupWindowView = View.inflate(getContext(), R.layout.popupwindow_layout, null); PopupWindow popupWindow=new PopupWindow(popupWindowView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); popupWindow.getContentView().measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); popupWindow.setBackgroundDrawable(new ColorDrawable(0)); int popHeight=popupWindow.getContentView().getMeasuredHeight(); popupWindow.showAsDropDown(view, 0, -popHeight);

其他弹出类的窗口类似!在获取width与height之前先进行测量!


最后

以上就是魁梧海燕最近收集整理的关于关于PopupWindow wrap_content 后获取高度宽度的全部内容,更多相关关于PopupWindow内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部