我从网站获取数据并放置在文本视图中,以便我可以使用setGravity(Gravity.CENTER)将其居中。但是,当我将文本视图放在警告对话框中时,我无法再向下滚动以查看消息的结尾。有人可以帮我解决这个问题吗?谢谢
TextView msg1=new TextView(Welcome.this);
//Takes data from a website
msg1.setText(Html.fromHtml(getText("http://www.cellphonesolutions.net/welcome-en")));
msg1.setGravity(Gravity.CENTER);
LinearLayout dialogLayout = new LinearLayout(Welcome.this);
dialogLayout.addView(msg1);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
AlertDialog welcome = new AlertDialog.Builder(Welcome.this).create();
welcome.setView(dialogLayout);
welcome.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//rest of the code....
答案 0 :(得分:5)
您可以尝试更改以下代码:
dialogLayout.addView(msg1);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
AlertDialog welcome = new AlertDialog.Builder(Welcome.this).create();
ScrollView scrollPane = new ScrollView(this);
scrollPane.addView(dialogLayout);
welcome.setView(scrollPane);