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());
这篇关于如何获得对话框大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获得对话框大小?


基础教程推荐
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 多个组件的复杂布局 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01