繁体   English   中英

警报对话框中的TextView不会向下滚动

[英]TextView inside an alert dialog won't scroll down

我正在从网站上获取数据并将其放置在文本视图中,以便可以使用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....

您可以尝试更改代码,如下所示:

    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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM