这是我的代码:
@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 - 如何在 Android 中设置 Alert Dialog 的高度和宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5576991/