這裏是我的代碼:如何在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
?
我已經嘗試過了。我只能以垂直方式滾動,但我需要以水平方式滾動。當我添加HorizontalScroll時它不起作用。然後在設置LayoutParams之後,我只獲得了相同的屏幕尺寸。 – 2011-04-07 07:04:32
如果您想水平滾動,請將'ScrollView'替換爲'HorizontalScrollView',並在達到最大寬度時自動添加水平滾動。但是,目前沒有小部件允許您在同一時間水平和垂直滾動(谷歌它)。但對話框將盡可能垂直拉伸。 – 2011-04-07 07:17:11
謝謝。我得到了水平滾動。但我需要全屏顯示警報。 – 2011-04-07 07:21:33