如何在Android中设置警报对话框的高度和宽度?

这是我的代码:
@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;    

    AlertDialog alertChoice = new AlertDialog.Builder(context).create();
    alertChoice.setTitle("Title");
    alertChoice.setView(ViewDialogScreen("Test"));    
    alertChoice.show();    
  }
  private View ViewDialogScreen(String strText) {
    LinearLayout llay = new LinearLayout(context);
    llay.setLayoutParams(new LayoutParams(320, 400));
    TextView tv = new TextView(context);
    tv.setText(strText);
    llay.addView(tv);
    return llay;
  }
我得到了如上所述的输出。 我需要以全屏/ 95%的屏幕尺寸显示
AlertDialog
。 我需要处理
Dialog
中的更多字段。 如何启用
AlertDialog
中的
HorizontalScrollview
?     
已邀请:
为了获得滚动行为,在你的布局中添加一个周围的
ScrollView
,这将使你的
ViewDialogScreen
方法:
private View ViewDialogScreen(String strText) {
    ScrollView scroll = new ScrollView(context);
    scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    LinearLayout llay = new LinearLayout(context);
    llay.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    TextView tv = new TextView(context);
    tv.setText(strText);
    scroll.addView(llay);
    llay.addView(tv);
    return scroll;
}
现在尝试添加更多字段,它应该滚动。     
我不确定这一点,但您可以为对话框设置自己的布局。请参阅我的答案Android:Dialog在不调用dismiss的情况下解散     
如果要自定义
AlertDialog
,则需要创建自定义
Dialog
。     

要回复问题请先登录注册