Android 如何在运行时找到自定义对话框的宽度和高度

Android 如何在运行时找到自定义对话框的宽度和高度,android,dialog,Android,Dialog,嗨,我正在创建一个自定义对话框。很好用。我被分配到的宽度是fill\u parent,高度是wrap\u content如何在运行时找到它们的宽度和高度。对于任何视图,都可以使用getHeight()和getWidth()方法获取高度和宽度信息 fill_parent wrap_content 有关更多信息,请参阅。试试这个 AlertDialog.Builder a = new AlertDialog.Builder(this); View v = a.create().getCurrent

嗨,我正在创建一个自定义对话框。很好用。我被分配到的宽度是fill\u parent,高度是wrap\u content如何在运行时找到它们的宽度和高度。

对于任何视图,都可以使用getHeight()和getWidth()方法获取高度和宽度信息

fill_parent wrap_content 有关更多信息,请参阅。

试试这个

AlertDialog.Builder a = new AlertDialog.Builder(this);

View v = a.create().getCurrentFocus();
v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

int height = v.getMeasuredHeight();
int width = v.getMeasuredWidth();

通过编程或xml布局为自定义对话框提供高度/宽度?我使用xml布局提供高度/宽度。如何通过编程知道它们的高度和宽度?谢谢。只有在活动中它才能正常工作。它在“自定义”对话框中不起作用。