【问题标题】:How to retrive a height of alertDialog with "wrap_content" layout? [duplicate]如何使用“wrap_content”布局检索alertDialog的高度? [复制]
【发布时间】:2016-07-04 20:05:10
【问题描述】:

我使用 Builder 制作了 alertDialog 并为它分配了这样的布局:

View view2 = LayoutInflater.from(getContext()).inflate(R.layout.information_dialog_layout, null);
    AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.ert).create();
    alertDialog.setView(view2);
    alertDialog.show();

但无法检索 px 中的对话框高度,也尝试了 'Rect' 类但没有帮助(虽然可能设置错误)...? P.S 我已经在 StackOverflow 上查找了类似问题的一些答案,但这些对我都不起作用:s

【问题讨论】:

  • 实际上view2.getMeasuredHeight()应该在显示对话框之后工作。
  • 它没有 - 得到“0”:s
  • @SakchhamSharma 对于 U 使用 Builder 的示例,答案不存在

标签: java android xml height android-alertdialog


【解决方案1】:

你可能想使用

view2.getHeight();

但结果会不准确。

但是

alertDialog.getWindow().getDecorView().getHeight();

是一个更好的选择,因为它会返回对话的实际高度,包括标题和按钮。只需确保在调用上述代码时对话具有焦点。

More Info

【讨论】:

  • 它也返回“0”:s - 当你说“有焦点”时,你的意思是把它放在“alerDialog.show() 之后?-还是我误解了?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
相关资源
最近更新 更多