【问题标题】:How to fix dialog's size in android如何在android中修复对话框的大小
【发布时间】:2014-03-13 12:07:27
【问题描述】:

我使用 android 的 Dialog 功能来读取登录信息。它运行良好,但登录对话框在不同手机中显示不同的显示尺寸。如何为所有设备固定相同的尺寸。

如下图所示

如何解决这个问题?

提前致谢

【问题讨论】:

  • 你需要设置对话框的高度和宽度。

标签: android android-layout android-dialog


【解决方案1】:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle("Title");
alertDialog = builder.create();
alertDialog.show();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.

alertDialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();

lp.copyFrom(alertDialog.getWindow().getAttributes());
lp.width = 150;
lp.height = 500;
lp.x=-170;
lp.y=100;
alertDialog.getWindow().setAttributes(lp);

【讨论】:

    【解决方案2】:

    您可以通过在运行时提供参数或创建自定义对话框来实现。 请检查此Android:How can I set the AlertDialog width and height,and the button of the AlertDialog style?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-27
      • 2011-09-27
      • 2016-09-27
      • 1970-01-01
      • 2012-11-09
      相关资源
      最近更新 更多