我希望在弹出窗口内使用自定义布局,所以我使用了AlertDialog。由于弹出窗口中子视图的数量是动态决定的,因此我使用了ScrollView。现在问题来了,当没有剩余空间并且滚动开始时,正面和负面按钮会变得不可见。 以下是代码:
AlertDialog.Builder dialog;
dialog = new AlertDialog.Builder(this);
dialog.setMessage("Please enter below parameters");
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
LinearLayout rootLayout = new LinearLayout(this);
rootLayout.setOrientation(LinearLayout.VERTICAL);
ScrollView scrollView = new ScrollView(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(50, 0, 50, 0);
try {
JSONArray data = new JSONArray(parameters);
String toastDaata = "";
for (int i = 0; i < data.length(); i++) {
JSONObject parameter = data.getJSONObject(i);
String sources = parameter.getString("sources");
String name = parameter.getString("name");
String mandatory = parameter.getString("mandatory");
toastDaata = toastDaata + "\n" + name + ":" + mandatory;
EditText editText$name = new EditText(this);
editText$name.setHint(name);
editText$name.setLayoutParams(params);
TextInputLayout textInputLayout = new TextInputLayout(this);
textInputLayout.setLayoutParams(params);
textInputLayout.addView(editText$name, params);
layout.addView(textInputLayout);
}
flowDescription.setText(toastDaata);
Toast.makeText(this, toastDaata, Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
scrollView.addView(layout);
rootLayout.addView(scrollView);
dialog.setView(rootLayout);
dialog.setNegativeButton("Cancel", null);
dialog.setPositiveButton("Go", null);
dialog.show();
根据图片,当需要滚动时,它会隐藏按钮。