Search code examples
androidandroid-layoutandroid-edittextandroid-tablelayout

Why won't an EditText wrap its lines when inside a TableLayout?


I noticed that when I put an EditText (or two) inside a single TableLayout row, the text won't wrap.

I'd like to understand what's going on here, and if there's any correct way to use a multi-line EditText (or two) inside a TableRow.

The below layout file:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TableRow>

        <EditText
            android:layout_width="match_parent"
            android:hint="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
            android:minLines="3" />
    </TableRow>

</TableLayout>

results in the following layout with no wrap (I presume the View is actually stretching beyond the right bounds of the screen.):

enter image description here

However, either adding android:stretchColumns="0" or omitting the TableRow tag works for one EditText but not two:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:layout_width="match_parent"
        android:hint="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
        android:minLines="3" />

</TableLayout>

enter image description here


Solution

  • Try using this as an EditText attribute:

    android:scrollHorizontally="false"