简体   繁体   中英

Android - Formatting a TextView

I created a simple word search which works in normal Java where it prints out a 2D array of the letters. Everything is perfectly inline and looking nice, but when trying to turn this into an android app, none of the letters are inline.

My code is the following:

TextView wordGrid = (TextView) findViewById(R.id.wordSearch);  
String grid = "";

    for(int i=0; i<matrix.length; i++)
    {
    grid += i + "   ";

        for(int j=0; j<matrix.length; j++)
        {
            grid +=  matrix[i][j] + " ";
        }
        grid += "\n";
    } 

    wordGrid.setText(grid);

The main.xml document contains the following attributes for 'wordSearch'

<TextView
android:id="@+id/wordSearch"
android:layout_width="400px"
android:layout_height="400px"
android:textSize="18sp"
android:layout_x="41dp"
android:layout_y="25dp" />

I can't get it to display all of the letters inline. Any help is greatly appreciated.

Thanks

尝试这个:

wordGrid.setText( Html.fromHtml( grid ) );

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