How to get dialog size?(如何获得对话框大小?)
问题描述
我正在寻找一种获取自定义对话框大小的方法.我经历了 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());
这篇关于如何获得对话框大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获得对话框大小?


- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01