下面是我的code:
@覆盖 公共无效的onCreate(捆绑savedInstanceState){ super.onCreate(savedInstanceState); 上下文=这一点; AlertDialog alertChoice =新AlertDialog.Builder(上下文).create(); alertChoice.setTitle(标题); alertChoice.setView(ViewDialogScreen(测试)); alertChoice.show(); } 私人查看ViewDialogScreen(字符串strText的){ 的LinearLayout llay =新的LinearLayout(背景); llay.setLayoutParams(新的LayoutParams(320,400)); TextView的电视=新的TextView(背景); tv.setText(strText的); llay.addView(电视); 返回llay; }
我得到的输出象上面。
我需要在全屏显示 AlertDialog
/屏幕尺寸的95%。 我需要在对话框
来处理更多的领域。如何让 HorizontalScrollview
在 AlertDialog
解决方案 要获得滚动行为,加上周围的滚动型
来布局,这将使你的 ViewDialogScreen
方法如下:
私人浏览ViewDialogScreen(字符串strText的){ 滚动型滚动=新的滚动型(上下文); scroll.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); 的LinearLayout llay =新的LinearLayout(背景); llay.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); TextView的电视=新的TextView(背景); tv.setText(strText的); scroll.addView(llay); llay.addView(电视); 返回滚动;}
现在尝试加入一些更多的领域,它应该滚动。
Here is my code:
@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;
}
I got the output like the above.
I need to show theAlertDialog
in full screen / 95% of the Screen size.
I need to handle more fields in the Dialog
.
How do I enable the HorizontalScrollview
in the AlertDialog
?
解决方案
to get the scrolling behaviour, add a surrounding ScrollView
to your layout, which would make your ViewDialogScreen
method to this:
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;
}
Now try adding some more fields and it should scroll.