如何获得对话框大小?(How to get dialog size?)

系统教程 行业动态 更新时间:2024-06-14 16:55:57
如何获得对话框大小?(How to get dialog size?) java

我正在寻找一种方法来获取自定义对话框的大小。 我经历了这个问题,但唯一给出的答案是无用的,因为如果我尝试mDialog.getWindow().getAttributes().height; 它只返回-2,这是我设置为对话的WRAP_CONTENT属性的常量。 我怎样才能得到它的大小。 我想知道背景图片的siye。

I am looking for a way to get size of a custom dialog. I went through this question, but the only answer given is pretty useless, because if I try mDialog.getWindow().getAttributes().height; it only returns -2, which is a constant for WRAP_CONTENT attribute which I set to dialog. How can I get the size of it. I want to know the siye for the background image.

最满意答案

实际上,在Android中,它不像iOS那样工作 - 但无法获得View本身的大小,但是您可以执行的操作是请求该视图的ROOT布局的大小。

例如:

myDialog.this.findViewById(R.id.dialog_root_layout).getHeight());

Actually, in Android it doesn't work like in iOS - you can't get the size of the View itself, what you can do, though, is to ask for the size of the ROOT layout of that view.

e.g.:

myDialog.this.findViewById(R.id.dialog_root_layout).getHeight());

更多推荐

本文发布于:2023-04-10 11:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/c1a670244bde7b8facd6d06c92da01c5.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   如何获得   大小   size   dialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!