【问题标题】:Alert dialog resizes when the content is changed更改内容时调整警报对话框的大小
【发布时间】:2012-11-22 15:27:26
【问题描述】:

I have this AlertDialog with and dynamic list in it(when a item from the list is selected the content of the list changes also).问题是初始对话框的高度与其父级匹配,但是当内容更改并且大小小得多时,对话框会包裹内容。我怎样才能避免这种情况?

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(); 
        }
    });
}

【问题讨论】:

  • 请向我们展示相关代码,例如您如何构建您的AlertDialog
  • public ExplorerDialog(Context context, final SettingsDialog settingsDialog, int fileType) { super(context); setIcon(R.drawable.dialog_explorer_file_manager); setTitle("浏览器对话框"); 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(); }});}

标签: android dialog resize height alert


【解决方案1】:

您的自定义对话框布局:

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));

【讨论】:

    【解决方案2】:

    您可能已将警报对话框的视图设置为列表,这是获得所需内容的快速方法:

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

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

    【讨论】:

    • d 应该是我的警报对话框吗?我已经尝试过了,仍在调整大小
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多