我想要在弹出窗口中使用自定义布局,所以我使用了警报对话框。由于弹出窗口中的子视图数量是动态决定的,所以我使用了 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();
根据图像,当需要滚动时,它会隐藏按钮。
试试这个..它对我有用......
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LinearLayout rootLayout = new LinearLayout(this);
rootLayout.setOrientation(LinearLayout.VERTICAL);
ScrollView scrollView = new ScrollView(MainActivity.this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
for (int i = 0; i < 20; i++) {
EditText editText$name = new EditText(this);
editText$name.setHint("Test");
TextInputLayout textInputLayout = new TextInputLayout(this);
textInputLayout.addView(editText$name);
layout.addView(textInputLayout);
}
scrollView.addView(layout);
rootLayout.addView(scrollView);
alertDialog.setNegativeButton("Cancel", null);
alertDialog.setPositiveButton("Go", null);
alertDialog.setView(rootLayout);
alertDialog.show();
与您相同的输出除外..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)