简体   繁体   中英

TextView inside an alert dialog won't scroll down

I am taking data from a website and placing inside of a text view so that I can center it using setGravity(Gravity.CENTER). However when i place the text view inside of the alert dialog I can no longer scroll down to see the end of my message. Can someone help me with this problem? Thank You

    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....

You can try changing the code like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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