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

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

问题描述

我正在寻找一种获取自定义对话框大小的方法.我经历了 this 问题,但是唯一给出的答案是没有用的,因为如果我尝试 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 布局的大小.

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天全站免登陆