【发布时间】:2014-03-13 12:07:27
【问题描述】:
我使用 android 的 Dialog 功能来读取登录信息。它运行良好,但登录对话框在不同手机中显示不同的显示尺寸。如何为所有设备固定相同的尺寸。
如下图所示
如何解决这个问题?
提前致谢
【问题讨论】:
-
你需要设置对话框的高度和宽度。
标签: android android-layout android-dialog
我使用 android 的 Dialog 功能来读取登录信息。它运行良好,但登录对话框在不同手机中显示不同的显示尺寸。如何为所有设备固定相同的尺寸。
如下图所示
如何解决这个问题?
提前致谢
【问题讨论】:
标签: android android-layout android-dialog
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);
【讨论】:
您可以通过在运行时提供参数或创建自定义对话框来实现。 请检查此Android:How can I set the AlertDialog width and height,and the button of the AlertDialog style?
【讨论】: