更改内容时,警报对话框会调整大小

时间:2012-12-04 21:44:12

标签: android dialog resize height alert

我有AlertDialog和动态列表(当列表中的项目被选中时,列表的内容也会发生变化)。问题是初始对话框的高度与其父级匹配,但是当内容更改且大小更小时,对话框会封装内容。我怎么能避免这个?

public ExplorerDialog(Context context, final SettingsDialog settingsDialog, int fileType) {  
    super(context); 

    setIcon(R.drawable.dialog_explorer_file_manager); 
    setTitle("Explorer Dialog"); 
    setView(LayoutInflater.from(context).inflate(R.layout.dialog_explorer_layout, null)); 
    setButton(BUTTON_POSITIVE, "Done", new OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
            settingsDialog.show(); 
        } 
    }); 

    setButton(BUTTON_NEGATIVE, "Cancel", new OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
            settingsDialog.show(); 
        }
    });
}

2 个答案:

答案 0 :(得分:1)

您可能已将alertdialog的视图设置为列表,这是获取所需内容的快捷方式:

 d.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, 600)

其中d是创建的对话框,这允许您设置宽度和高度的值。

答案 1 :(得分:0)

您的自定义对话框布局:

LinearLayout dialoglayout = (LinearLayout) dialog.findViewById(R.id.dialoglayout);

dialoglayout.setLayoutParams(new FrameLayout.LayoutParams(700,1100));

如果你想要屏幕尺寸的宽度:

dialoglayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,1100));