如何获取对话框大小? [英] How to get dialog size?

查看:190
本文介绍了如何获取对话框大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 布局的大小查看。

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.

例如:

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

这篇关于如何获取对话框大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆